try, catch |
Execute statements and catch resulting errors |
MException |
Capture error information |
Capture Information About Exceptions
When a program throws an exception, information about
what caused the error is captured in an MException
object.
If you catch the exception before your program aborts, you can access
the information. You can also create MException
objects
that you use to throw exceptions in your code.
Detect conditions that keep your program from completing as expected or generate erroneous results, and then halt execution and throw an exception that reports the error.
To handle an exception appropriately for a particular
condition, capture information about the exception with a try/catch
statement
and then execute code to deal with the situation.
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.