lasterror
-- reproduce the
last errorlasterror
()
reproduces the last error that
occurred in the current MuPAD session.
lasterror()
lasterror
is used to reproduce errors that
were caught by traperror
. Cf. example 2.lasterror
is a function of the system kernel.We produce an error:
>> x := 0: y := 1/x
Error: Division by zero
This error may be reproduced by
lasterror
:
>> lasterror()
Error: Division by zero
A further error is produced:
>> error("my error")
Error: my error
>> lasterror()
Error: my error
>> delete x, y:
The following procedure mysin
computes the
sine function of its argument. In case of an error produced by the
system function sin
, it
prints information on the argument and reproduces the error:
>> mysin := proc(x) local result; begin if traperror((result := sin(x))) = 0 then return(result) else print(Unquoted, "the following error occurred " . "when calling sin(".expr2text(x)."):"); lasterror() end_if: end:
Indeed, the system's sine function produces an error for large floating point arguments:
>> mysin(1.0*10^100)
the following error occurred when calling sin(10.0e99): Error: Loss of precision; during evaluation of 'sin'
>> delete mysin: