Exception Handling
Capture data on errors
Any MATLAB® code that detects an error and throws an exception constructs
an MException
object. MATLAB can throw either predefined exceptions or exceptions that you
construct.
Functions
try, catch | Execute statements and catch resulting errors |
MException | Capture error information |
addCause | Record additional causes of exception |
addCorrection | Provide suggested fix for exception |
getReport | Get error message for exception |
MException.last | Return last uncaught exception |
rethrow | Rethrow previously caught exception |
throw | Throw exception |
throwAsCaller | Throw exception as if occurs within calling function |
matlab.lang.correction.AppendArgumentsCorrection | Correct error by appending missing input arguments |
matlab.lang.correction.ConvertToFunctionNotationCorrection | Correct error by converting to function notation |
matlab.lang.correction.ReplaceIdentifierCorrection | Correct error by replacing identifier in function call |
Topics
- Exception Handling in a MATLAB Application
It is a good programming practice to include error checking in your programs to ensure reliable operation under all conditions. You can decide how your programs respond to different types of errors.