Main Content

getReport

获取异常的错误消息

说明

示例

msgText = getReport(exception) 获取异常错误消息并以格式化文本 msgText 的形式返回。消息是 MException 对象 exceptionmessage 属性的值。这是 MATLAB® 在引发异常时显示的相同文本。

示例

msgText = getReport(exception,type) 使用由 type 指定的特定详细信息级别返回错误消息。

示例

msgText = getReport(exception,type,'hyperlinks',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 中创建以下函数。

function a = testFunc
try
    a = notaFunction(5,6);
catch a

end

由于函数 notaFunction 不存在,testFunc 返回一个 MException 对象。

在命令提示符处,调用 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'.

导致 MATLAB 引发异常。

try 
    surf
catch exception
end

从异常获取错误消息。

msgText = getReport(exception)
msgText =

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

获取错误消息,但没有指向 surf.m 的有效超链接。

msgText = getReport(exception,'extended','hyperlinks','off')
msgText =

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

输入参数

全部折叠

提供错误消息的异常对象,指定为标量 MException 对象。

返回的消息的详细级别指示符,指定为 'extended''basic'

typemsgText 详细信息级别
'extended'(默认值)msgText 包含行号、错误消息、原因和堆栈摘要。要显示合适的堆栈,MATLAB 首先必须引发异常。
'basic'msgText 包含错误消息。

扩展功能

基于线程的环境
使用 MATLAB® backgroundPool 在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool 加快代码运行速度。

版本历史记录

在 R2007b 中推出

另请参阅

| |