Main Content

MException.last

返回最后未捕获的异常

说明

示例

exception = MException.last 返回最近引发的、未捕获的 MException 对象的内容。如果 try/catch 语句捕获到了最后一个异常,则不设置 MException.lastMException.last 是静态函数。

示例

MException.last('reset') 清除从 MException.last 返回的异常的属性。它将 MException identifiermessage 属性设置为空字符向量,将 stack 属性设置为 0×1 结构体,将 cause 属性设置为一个空的元胞数组。

示例

全部折叠

导致 MATLAB® 引发异常,但不缓存异常。

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

获取未捕获的异常。

exception = MException.last
exception = 

  MException with properties:

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

调用无输入参量的 surf 函数。

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

获取未捕获的异常。

exception = MException.last
exception = 

  MException with properties:

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

获得最后未捕获的异常。

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

  MException with properties:

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

提示

  • 仅从命令行窗口(而不是在函数内)使用 MException.last

版本历史记录

在 R2007b 中推出

另请参阅

| |