Darwin Help

Back to Index

error

Function error - terminate execution and issue an error message

Calling Sequence  error(msg,...)
Parameters
NameTypeDescription

msg anythingusually an error message
... anythingadditional arguments to clarify the error
Return Type  NULL
Synopsis This function returns to the top level of execution and issues the error message msg. If an error happens while executing a traperror() function, then the flow will not return to the top level, instead the traperror function will return with the value of the argument(s) of error(). When this happens, the global variable "lasterror" is set to the value of the error, else it is unassigned. Using error/traperror allows for a simple throw-catch mechanism.
Examples
> f := proc(x) if x=0 then error('oops, div by 0') fi; 5/x end;
f := proc (x) if x = 0 then error(oops, div by 0) fi; 5/x end
> f(0);
Error, (in f) oops, div by 0
> traperror(f(0));
oops, div by 0
> lasterror;
oops, div by 0


See also lasterror,   traperror