MATLAB Function Reference Previous page   Next Page
lasterr

Return last error message

Syntax

Description

msgstr = lasterr returns the last error message generated by MATLAB.

[msgstr, msgid] = lasterr returns the last error in msgstr and its message identifier in msgid. If the error was not defined with an identifier, lasterr returns an empty string for msgid. See Message Identifiers and Using Message Identifiers with lasterr in the MATLAB documentation for more information on the msgid argument and how to use it.

lasterr('new_msgstr') sets the last error message to a new string, new_msgstr, so that subsequent invocations of lasterr return the new error message string. You can also set the last error to an empty string with lasterr('').

lasterr('new_msgstr', 'new_msgid') sets the last error message and its identifier to new strings new_msgstr and new_msgid, respectively. Subsequent invocations of lasterr return the new error message and message identifier.

[msgstr, msgid] = lasterr('new_msgstr', 'new_msgid') returns the last error message and its identifier, also changing these values so that subsequent invocations of lasterr return the message and identifier strings specified by new_msgstr and new_msgid respectively.

Examples

Example 1

Here is a function that examines the lasterr string and displays its own message based on the error that last occurred. This example deals with two cases, each of which is an error that can result from a matrix multiply:

If you call this function with matrices that are incompatible for matrix multiplication (e.g., the column dimension of A is not equal to the row dimension of B), MATLAB catches the error and uses lasterr to determine its source:

Example 2

Specify a message identifier and error message string with error:

In your error handling code, use lasterr to determine the message identifier and error message string for the failing operation:

See Also

error, lasterror, warning, lastwarn


Previous page  kron lasterror Next page

© 1994-2005 The MathWorks, Inc.