MATLAB 帮助中心
返回最后未捕获的异常
exception = MException.last
MException.last('reset')
exception = MException.last 返回最近抛出的、未捕获的 MException 对象的内容。如果 try/catch 语句捕获到了最后一个异常,则不设置 MException.last。MException.last 是静态函数。
exception
MException
try/catch
MException.last
示例
MException.last('reset') 清除从 MException.last 返回的异常的属性。它将 MException identifier 和 message 属性设置为空字符向量,将 stack 属性设置为 0×1 结构体,将 cause 属性设置为一个空的元胞数组。
identifier
message
stack
cause
全部折叠
导致 MATLAB® 抛出异常,但不缓存异常。
A = 25; A(2)
Index exceeds matrix dimensions.
获取未捕获的异常。
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 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 中推出
try, catch | error | throw
try, catch
error
throw
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处