Execute statements and catch resulting errors
trystatementscatchexceptionstatementsend
try executes
the statements in the statements,
catch statements endtry block and catches resulting
errors in the catch block. This approach allows
you to override the default error behavior for a set of program statements.
If any statement in a try block generates an error,
program control goes immediately to the catch block,
which contains your error handling statements.
exception is an MException object
that allows you to identify the error. The catch block
assigns the current exception object to the variable in exception.
Both try and catch blocks
can contain nested try/catch statements.
You cannot use multiple catch blocks
within a try block, but you can nest complete try/catch blocks.
Unlike some other languages, MATLAB does not
allow the use of a finally block within try/catch statements.