To make your code more robust, check for edge cases and problematic
conditions. The simplest approach is to use an
switch statement to check for a specific condition,
and then issue an error or warning.
allow you to catch and respond to any error.
|Execute statements and catch resulting errors|
To flag unexpected conditions when running a program, issue a warning. To flag fatal problems within the program, throw an error. Unlike warnings, errors halt the execution of a program.
Your program might issue warnings that do not always adversely affect
execution. To avoid confusion, you can hide warning messages during execution by
changing their states from
You can save the warning current states, modify warning states, and restore the original warning states. This technique is useful if you temporarily turn off some warnings and later reinstate the original settings.
You can control how warnings appear in MATLAB®, including the display of warning suppression information and stack traces.
try/catch statement to execute code after your
program encounters an error.
It is a good programming practice to leave your program environment in a clean state that does not interfere with any other program code.