Documentation Center

  • Trial Software
  • Product Updates

getReport (MException)

Get error message for exception

Syntax

msgString = getReport(exception)
msgString = getReport(exception, type)
msgString = getReport(exception, type, 'hyperlinks', value)

Description

msgString = getReport(exception) returns a formatted message string, msgString, from an exception. This exception is represented by the exception input which is a scalar object of the MException class. The message string returned by getReport is the same as the error message displayed by MATLAB® when it throws this exception.

msgString = getReport(exception, type) returns a message string that either describes just the error (basic type), or shows the error and the stack as well (extended type). The type argument, when used, must be the second argument in the input argument list. See Examples , below.

type OptionDisplayed Text
'extended'Display line number, error message, and cause and stack summary (default)
'basic'Display line number and error message

msgString = getReport(exception, type, 'hyperlinks', value) returns a message string that either does or does not include active hyperlinks to the failing lines in the code. See the table below for the valid choices for value. The hyperlinks and value arguments, when used, must be the third and fourth arguments in the input argument list.

value OptionAction
'on'Display hyperlinks to failing lines (default)
'off'Do not display hyperlinks to failing lines
'default'Use the default for the Command Window to determine whether or not to use hyperlinks in the error message

Examples

This function attempts to read from a file that does not exist. When you call it, pass either ‘basic' or ‘extended' to specify the type of report you want to see displayed:

function line = test_getreport(file, rpttype)
try
    line = read_file(file);
catch exc
    getReport(exc, rpttype)
end

function line = read_file(file)
    fid = fopen(file, 'r');
    line = fread(fid);

The basic option displays only the error message:

test_getreport('filethatdoesnotexist.txt', 'basic')
ans =
Error using fread
Invalid file identifier.  Use fopen to generate a valid file identifier.

The extended option displays the error message and error call stack:

test_getreport('filethatdoesnotexist.txt', 'extended')
ans =
Error using fread
Invalid file identifier.  Use fopen to generate a valid file identifier.
Error in test_getreport>read_file (line 10)
    line = fread(fid);
Error in test_getreport (line 3)
    line = read_file(file);

See Also

| | | | | | | |

Was this topic helpful?