Problem 44357. Back to basics: throwing errors / exceptions
Throwing and handling errors (or exceptions) is an important part of practical programming.
Here your task is to provide an alternative to the built in elementwise division operator ./ (equivalent to the rdivide function) with the following differences:
- throws an error if any of the input elements have a non-zero imaginary component (and are therefore 'complex numbers' that are incapable of being correctly represented as real numbers);
- throws an error if any of the input elements are character arrays;
- yields NaN wherever the divisor (i.e. the denominator) is equal to zero.
This concept is analogous to the built in MATLAB function "realsqrt".
The first error must generate an MException with the following properties: identifier = 'realDivision:complexInput', message = 'The realDivision function only operates on real inputs.'.
The second error must generate an MException with the following properties: identifier = 'realDivision:incompatibleInput', message = 'The realDivision function is not defined for character inputs.'.
All other behaviour should be identical to the mrdivide function. Any exceptions that would have been thrown by mrdivide should also be thrown by your function — with the same contents of the identifier and message fields.
Note that the difference in MATLAB between errors and exceptions is somewhat fraught.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
234 Solvers
-
Matrix with different incremental runs
125 Solvers
-
Solve the set of simultaneous linear equations
419 Solvers
-
Cell Counting: How Many Draws?
1901 Solvers
-
When can one be the Life Member of the IEEE?
74 Solvers
More from this Author32
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!