Documentation

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.

lasterror

Reproduce the last error

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.

Syntax

lasterror()

Description

lasterror() reproduces the last error that occurred in the current MuPAD® session.

Typically, lasterror is used to reproduce errors that were caught by traperror. Cf. Example 2.

Examples

Example 1

We produce an error:

x := 0: y := 1/x
Error: Division by zero. [_invert]

This error may be reproduced by lasterror:

lasterror()
Error: Division by zero. [_invert]

A further error is produced:

error("my error")
Error: my error
lasterror()
Error: my error
delete x, y:

Example 2

The following procedure myln computes the ln function of its argument. In case of an error produced by the system function ln, it prints information on the argument and reproduces the error:

myln := proc(x)
  local result;
begin
  if traperror((result := ln(x))) = 0 then
     return(result)
  else
     print(Unquoted, "the following error occurred " .
                     "when calling ln(".expr2text(x)."):");
     lasterror()
  end_if:
end:

Indeed, the ln has a singularity at 0 and produces:

myln(0)
the following error occurred when calling ln(0):
Error: Singularity. [ln]
  Evaluating: myln
delete myln:

See Also

MuPAD Functions

Was this topic helpful?