chickadee » chicken » exceptions » handle-exceptions

(handle-exceptions var handle-expr expr1 expr2 ...)syntax

Evaluates the body expressions expr1, expr2, ... in sequence with an exception handler constructed from var and handle-expr. Assuming no exception is raised, the result(s) of the last body expression is(are) the result(s) of the handle-exceptions expression.

The exception handler created by handle-exceptions restores the dynamic context (continuation, exception handler, etc.) of the handle-exceptions expression, and then evaluates handle-expr with var bound to the value provided to the handler.


(handle-exceptions exn
		     (display "Went wrong")
 (car '()))
; displays "Went wrong"
(handle-exceptions exn 
		    ((eq? exn 'one) 1)
		     (else (abort exn)))
  (case (random 3)
   [(0) 'zero]
   [(1) (abort 'one)]
   [else (abort "Something else")]))
;=> 'zero, 1, or (abort "Something else")