【发布时间】:2018-08-08 09:01:43
【问题描述】:
我想捕捉一个异常,但打印如果没有捕捉到它会打印的相同消息(堆栈跟踪)。该怎么做?
我试过了
>> myfunctionwitherror
Error using myfunctionwitherror (line 3)
myerror
>> try myfunctionwitherror; catch disp(lasterror), end
Warning: This try-catch syntax will continue to work in R2007b, but may be illegal or may mean something different in future releases of MATLAB.
See MATLAB R2007a Release Notes, "Warning Generated by try-catch" for details.
MException with properties:
identifier: ''
message: 'myerror'
cause: {0×1 cell}
stack: [0×1 struct]
>> try myfunctionwitherror, catch e getReport(e), end
Warning: This try-catch syntax will continue to work in R2007b, but may be illegal or may mean something different in future releases of MATLAB.
See MATLAB R2007a Release Notes, "Warning Generated by try-catch" for details.
Undefined function or variable 'e'.
如何做到这一点?
我正在使用2016b。我不知道为什么会出现此消息。
【问题讨论】:
-
你用的是2007a,按一下?
-
@AnderBiguri 不,看我的更新
-
@SardarUsama 我原以为
e会接受异常对象,但这可能不适用于单行代码 -
您好。你还有这个问题吗?您需要更多帮助吗?
标签: matlab exception try-catch warnings stack-trace