protect unwind
protect unwind — evaluates protected code, despite errors.
protect statement unwind statement
statementAny Gamma or Lisp statement.
If no error occurs, the result of evaluating the protect
statement and the unwind
statement. If an error occurs, the result of the
unwind statement only.
This function ensures that a piece of code will be evaluated, even if an
error occurs within the protect statement code. This
is typically used when an error might occur but cleanup code has to be
evaluated even in the event of an error. The error condition will not be
cleared by this statement. If an error occurs, control will be passed to the
innermost trap_error function or to the outer level
error handler immediately after the unwind statement
is evaluated.
This code will close its file and run a
write_all_output function even if an error
occurs.
if (fp=open("filename","w"))
{
protect close(fp); unwind write_all_output();
}