Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

MException.last

Class: MException

Return last uncaught exception

Syntax

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

Description

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

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

expand 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.

Introduced in R2007b

Was this topic helpful?