Main Content

getReport

Get error message for exception

Description

msgText = getReport(exception) gets the error message for an exception and returns it as formatted text, msgText. The message is the value of the message property of the MException object, exception. It is the same text that MATLAB® displays when it throws the exception.

example

msgText = getReport(exception,type) returns the error message using the indicated level of detail, specified by type.

example

msgText = getReport(exception,type,'hyperlinks',hlink) uses the value of hlink to determine whether to include active hyperlinks to the failing lines of code within the error message.

example

Examples

collapse all

Cause MATLAB to throw an exception.

plus
Error using +
Not enough input arguments.

Get the error message from the exception.

exception = MException.last;
msgText = getReport(exception)
msgText =

Error using +
Not enough input arguments.

In a file in your current working folder, create the following function in testFunc.m.

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

end

Since the function, notaFunction, does not exist, testFunc returns an MException object.

At the command prompt, call testFunc and get the error message.

m = testFunc;
msgText = getReport(m)
msgText =

Undefined function 'notaFunction' for input arguments of type 'double'.

Error in testFunc (line 3)
    a = notaFunction(5,6);

Specify that the error message only contains the error message and not the stack information.

msgText = getReport(m,'basic')
msgText =

Undefined function 'notaFunction' for input arguments of type 'double'.

Cause MATLAB to throw an exception.

try 
    surf
catch exception
end

Get the error message from the exception.

msgText = getReport(exception)
msgText =

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

Get the error message without active hyperlinks to surf.m.

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

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

Input Arguments

collapse all

Exception object that provides the error message, specified as a scalar MException object.

Detail indicator of the message returned, specified as 'extended' or 'basic'.

type ValuemsgText Detail Level
'extended' (default)msgText includes the line number, error message, cause, and stack summary. To display the proper stack, MATLAB first must throw an exception.
'basic'msgText includes the error message.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2007b

See Also

| |