This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Retrieve the last error number and text

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




getlasterror() returns the last error that occurred in the current MuPAD® session, as a list of the error number and the error string.

After an error has occurred (whether visible or caught by traperror), getlasterror will return both the error number (as returned by traperror) and the error string.

In a MuPAD session where no errors occurred, getlasterror returns the list [0, ""]. This is also true after a call to reset().


Note that the MuPAD library uses traperror itself and that getlasterror() may return errors that have been caught and properly handled by the library already. You should not use getlasterror to detect errors, use the return value of traperror instead!


Example 1

In a fresh session, getlasterror returns a list indicating “no errors yet”:


After an error has been thrown, getlasterror returns the corresponding number and string:

Error: Singularity. [ln]

This includes errors not displayed because of traperror:

traperror(solve(a, b, c))


Return Values

List of an integer and a string

See Also

MuPAD Functions

Was this topic helpful?