trap_error
trap_error — traps errors in the body code.
trap_error (!body, !error_body)
bodyAny Gamma or Lisp expression.
error_bodyAny Gamma or Lisp expression.
The result of the body, unless an error occurs
during its evaluation, in which case the result of evaluating the
error_body.
This function traps any errors which occur while evaluating the
body code. If no error occurs, then
trap_error will finish without ever evaluating the
error_body. If an error does occur,
trap_error will evaluate the
error_body code immediately and the error
condition will be cleared. This is usually used to protect a running program
from a piece of unpredictable code, such as an event handler. If the error
is not trapped it will be propagated to the top-level error handler where it
will cause the interpreter to go into an interactive debugging session.
The following piece of code will run an event loop and protect against an unpredictable event.
while(t)
{
trap_error(next_event(),print_trapped_error());
}
function print_trapped_error ()
{
princ("Error\n", _error_stack_, "\n occurred...\n");
princ("Clearing error condition and continuing.\n");
}