MException.last

Returns the most recent exception that was raised.

Category: Programming > Programming Utilities

Syntax

ME = MException.last

Returns the last exception object recorded in the session.

Description

This is a static method of the MException class. It records the latest error even when it was caught, so it lets a script look back at a failure after the catch block has ended. Reading it does not change it.

Output arguments

ME
An MException. Before any error has occurred its message and identifier are empty.

Example

Looking back at the last error

try
    error('a:b', 'oops')
catch
end
ME = MException.last;
disp(ME.message)
disp(ME.identifier)
Output
oops
a:b

See also

MException lasterr try, catch getReport