lasterror

Reproduce the last error

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

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?