Main Content

MException.last

Return last uncaught exception

Description

example

exception = MException.last returns the contents of the most recently thrown, uncaught MException object. MException.last is not set if a try/catch statement catches the last exception. MException.last is a static function.

example

MException.last('reset') clears the properties of the exception returned from MException.last. It sets the MException identifier and message properties to an empty character vector, the stack property to a 0-by-1 structure, and the cause property to an empty cell array.

Examples

collapse all

Cause MATLAB® to throw, but not catch, an exception.

A = 25;
A(2)
Index exceeds matrix dimensions.

Get the uncaught exception.

exception = MException.last
exception = 

  MException with properties:

    identifier: 'MATLAB:badsubscript'
       message: 'Index exceeds matrix dimensions.'
         cause: {}
         stack: [0x1 struct]

Call the surf function with no input arguments.

surf
Error using surf (line 49)
Not enough input arguments.

Get the uncaught exception.

exception = MException.last
exception = 

  MException with properties:

    identifier: 'MATLAB:narginchk:notEnoughInputs'
       message: 'Not enough input arguments.'
         cause: {}
         stack: [1x1 struct]

Get the last, uncaught exception.

MException.last('reset')
exception = MException.last
exception = 

  MException with properties:

    identifier: ''
       message: ''
         cause: {0x1 cell}
         stack: [0x1 struct]

Tips

  • Use MException.last only from the Command Window, not within a function.

See Also

| |

Introduced in R2007b