Download MuPAD User's Guide

Transcript
5
Programming Fundamentals
g := proc(n:Type::PosInt)
local test;
begin
test := proc()
begin
if n > 10 then
error("The number must not exceed 10.")
end_if
end_proc:
if traperror(test(n)) <> 0 then
g(n - 1)
else
n!
end_if;
end_proc:
Call the procedure with the number 100. During run time, the procedure encounters
the error, but does not terminate. It also does not display the error message. Instead, it
returns the result:
g(100)
To retrieve and display the error message caught during execution of the procedure g,
use the lasterror function:
lasterror()
Error: The number must not exceed 10. [test]
To display the error code and the text of that message, use the getlasterror function:
g(100):
getlasterror()
5-94