lasterr
Returns the message of the most recent error.
Category: Programming > Functions
Syntax
msg = lasterr
Returns the last error message.
[msg, id] = lasterr
Also returns its identifier.
lasterr(msg, id)
Sets the stored message and identifier.
Description
Every error raised in the session, even one caught by try, updates the stored message. lasterr reads it back, which was the older way to inspect an error after an empty catch. Prefer catch err and use err.message and err.identifier, which belong to one specific error.
Input arguments
msg- Message to store.
id- Identifier to store.
Output arguments
msg- Text of the last error; empty if none occurred.
id- Identifier of the last error.
Example
Reading the last error
try
error('Demo:fail', 'boom %d', 2);
catch
end
[msg, id] = lasterr
Output
msg = 'boom 2'
id = 'Demo:fail'