MATLAB 帮助中心
获取异常的错误消息
msgText = getReport(exception)
msgText = getReport(exception,type)
msgText = getReport(exception,type,'hyperlinks',hlink)
msgText = getReport(exception) 获取异常错误消息并以格式化文本 msgText 的形式返回。消息是 MException 对象 exception 的 message 属性的值。这是 MATLAB® 在抛出异常时显示的相同文本。
msgText
exception
MException
message
示例
msgText = getReport(exception,type) 使用由 type 指定的特定详细信息级别返回错误消息。
type
msgText = getReport(exception,type,'hyperlinks',hlink) 使用 hlink 的值确定是否将失败代码行的有效超链接包含在错误消息内。
hlink
全部折叠
导致 MATLAB 抛出异常。
plus
Error using + Not enough input arguments.
从异常获取错误消息。
exception = MException.last; msgText = getReport(exception)
msgText = Error using + Not enough input arguments.
在当前工作文件夹下的文件中,在 testFunc.m 中创建以下函数。
testFunc.m
function a = testFunc try a = notaFunction(5,6); catch a end
由于函数 notaFunction 不存在,testFunc 返回一个 MException 对象。
notaFunction
testFunc
在命令提示符处,调用 testFunc 并获取错误消息。
m = testFunc; msgText = getReport(m)
msgText = Undefined function 'notaFunction' for input arguments of type 'double'. Error in testFunc (line 3) a = notaFunction(5,6);
指定错误消息仅包含错误消息,不包含堆栈信息。
msgText = getReport(m,'basic')
msgText = Undefined function 'notaFunction' for input arguments of type 'double'.
try surf catch exception end
msgText = Error using surf (line 49) Not enough input arguments.
获取错误消息,但没有指向 surf.m 的有效超链接。
surf.m
msgText = getReport(exception,'extended','hyperlinks','off')
提供错误消息的异常对象,指定为标量 MException 对象。
'extended'
'basic'
返回的消息的详细级别指示符,指定为 'extended' 或 'basic'。
'default'
'on'
'off'
消息的超链接指示符,包含指向失败代码行的有效超链接,指定为 'default'、'on' 或 'off'。
全部展开
backgroundPool
ThreadPool
在 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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处