MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Capture Information About Exceptions


In this section...
“Overview” on page 26-5
“The MException Class” on page 26-5
“Properties of the MException Class” on page 26-6
“Methods of the MException Class” on page 26-14

Overview


When MATLAB throws an exception, it captures information about the cause in a data
structure called an MException object. This object is an instance of the MATLAB
MException class. You can access the MException object by catching the exception
before your program aborts and accessing the object constructed for this particular error
via the catch command. When throwing an exception in response to an error in your own
code, you will have to create a new MException object and store information about the
error in that object.

This section describes the MException class and objects constructed from that class.

Information on how to use this class is presented in later sections on “Respond to an
Exception” on page 26-19 and “Throw an Exception” on page 26-16.

The MException Class


The figure shown below illustrates one possible configuration of an object of the
MException class. The object has five properties: identifier, message, stack,
cause, and Correction. Each of these properties is implemented as a field of the
structure that represents the MException object. The stack field is an N-by-1 array of
additional structures, each one identifying a function, and line number from the call
stack. The cause field is an M-by-1 cell array of MException objects, each representing
an exception that is related to the current one.

See “Properties of the MException Class” on page 26-6 for a full description of these
properties.

Capture Information About Exceptions
Free download pdf