protect unwind

protect unwind — evaluates protected code, despite errors.

Syntax

protect statement unwind statement

		

Arguments

statement

Any Gamma or Lisp statement.

Returns

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.

Description

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.

Example

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();
}
		

See Also

error, Statements, try catch, Tutorial II Error Handling