Documentation

MException.last

Class:MException

Return last uncaught exception

Syntax

异常= MException.last
MException.last('reset')

Description

异常= MException.lastreturns the contents of the most recently thrown, uncaughtMExceptionobject.MException.lastis not set if the last exception is caught by atry/catchstatement.MException.lastis a static method of theMExceptionclass.

MException.last('reset')clears the properties of the exception returned fromMException.last. It sets theMExceptionidentifierandmessageproperties to an empty character vector, the堆栈property to a 0-by-1 structure, and thecauseproperty 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.

异常= MException.last
异常= MException with properties: identifier: 'MATLAB:badsubscript' message: 'Index exceeds matrix dimensions.' cause: {} stack: [0x1 struct]

Call thesurffunction with no input arguments.

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

Get the uncaught exception.

异常= MException.last
异常= 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
异常= MException with properties: identifier: '' message: '' cause: {0x1 cell} stack: [0x1 struct]

Tips

  • UseMException.lastonly from the Command Window, not within a function.

Introduced in R2007b

Was this topic helpful?