error
-- raise a user-specified
exceptionerror(
message)
aborts the current
procedure, returns to the interactive level, and displays the error
message message
.
error(message)
message |
- | the error message: a string |
The formatting of the output of error
is sensitive to
the environment variable TEXTWIDTH
.
lasterror
,
prog::error
, traperror
, warning
error(
message)
aborts the
current procedure with an error. If the
error is not caught via traperror
by a procedure that has
directly or indirectly called the current procedure, control is
returned to the interactive level, and the string message
is printed as an error message.Error: message
[name]
, where name
is the name of the procedure
containing the call to error
. See the examples.traperror
. If an error occurs
while the arguments of traperror
are evaluated, control
is returned to the procedure containing the call to traperror
and not to the
interactive level. No error message is printed. The return value of
traperror
is
1028
when it catches an error raised by
error
; see example 2.error
is useful to raise an error in the
type checking part of a user-defined procedure, when this procedure is called with
invalid arguments.error
is a function of the system kernel.If the divisor of the following simple division routine
is 0
, then an error is raised:
>> mydivide := proc(n, d) begin if iszero(d) then error("Division by 0") end_if; n/d end_proc: mydivide(2, 0)
Error: Division by 0 [mydivide]
When the error is raised in the following procedure
p
, control is returned to the interactive level
immediately. The second call to print
is never executed. Note that the
procedure's name is printed in the error message:
>> p := proc() begin print("entering procedure p"); error("oops"); print("leaving procedure p") end_proc: p()
"entering procedure p" Error: oops [p]
The following procedure q
calls the
procedure p
and catches any error that is raised
within p
:
>> q := proc() begin print("entering procedure q"); print("caught error: ", traperror(p())); print("leaving procedure q") end_proc: q()
"entering procedure q" "entering procedure p" "caught error: ", 1028 "leaving procedure q"