unwind_protect
unwind_protect — ensures code will be evaluated, despite errors in the body
code.
unwind_protect (!body, !protected_body)
bodyAny Gamma or Lisp expression.
protected_bodyAny Gamma or Lisp expression.
The result of evaluating the protected_body code.
If an error occurs then this function does not return.
This function ensures that a piece of code will be evaluated, even if an
error occurs within the body 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
function. If an error occurs then control will be passed to the innermost
trap_error function or to the outer level error
handler immediately after the protected_body is
evaluated.
The following code will close its file and run a
write_all_output function even if an error
occurs.
if (fp=open("filename","w"))
{
unwind_protect(write_all_output(),close(fp));
}