next up previous contents index
Next: Collections Up: Control structures Previous: Looping and closures

Exception handling

A couple of methods are defined on closures to specialize error and exception handling.

In error.cecil:


method handle_system_errors(cl:&():void):bool; 
The handle_system_errors method executes its argument closure. Any Cecil errors (e.g., error or exit calls) caused during evaluation of the closure are caught and suppressed. The boolean return value indicates whether an error occurred.


method unwind_protect(cl:&():`T, on_return:&():void):T; 
The unwind_protect method allows a ``clean up'' closure to be executed whenever control returns through the unwind_protect method call, either normally, via a non-local return, or via a Cecil error. The cl closure is invoked. When control returns from this invocation, the on_return closure is invoked. When this closure completes, the returning of the cl closure is resumed. If the cl closure returned normally, the result of this closure is returned as the result of the unwind_protect method; otherwise it continues to throw whatever exception the body did. (unwind_protect is similar to the like-named construct in Common Lisp.)


next up previous contents index
Next: Collections Up: Control structures Previous: Looping and closures

The Cecil project