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.
Outputs
- msg
- A string: message of the last error.
Examples
error('this is my error message.');
msg = lasterr()
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.