lasterr

Get or set the last error message.

Syntax

msg = lasterr()

lasterr(new_message)

Inputs

new message
Message to set as the last message error.
Type: char | string
Dimension: string

Outputs

msg
A string: message of the last error.

Examples

error('this is my error message.');
msg = lasterr()
In this example, the function eps('toto') raises an error; the error message should display:
message_computed = '';
try
  eps('toto')
catch
  message_computed = lasterr();
end
expected_message = 'Error: invalid class name';
if strcmp(message_computed, expected_message) ~= 1
  error('it is not the error expected.');
end	

Comments

lasterr() is generally used with try catch statement to compare the error message and do an action in response of this error. lasterr('') can be used to reset the last error message. Clear does not modify the last error message.