Next: , Previous: , Up: iklib unwind-protect   [Index]


6.9.5 Raising continuable exceptions from the thunk

A continuable exception is raised with raise-continuable and it is a way to resume the execution of a chunk of code after raising an exception. This example shows the basic mechanism:

(import (rnrs))
(with-exception-handler
    (lambda (E)
      (+ E 2))
  (lambda ()
    (raise-continuable 1)))
⇒ 3

The handling of a continuable exception can be the same of the handling of a non–continuable exception; in addition the exception handler is allowed to return. In the latter case the dynamic extent of the call to ?thunk is not exited, so ?unwind-handler is not called.

The following example shows what happens when ?thunk raises a continuable exception:

(import (vicare)
  (only (vicare checks)
        with-result
        add-result))

(with-result
  (with-exception-handler
      (lambda (E)
        (add-result 'exception-handler)
        (+ E 2))
    (lambda ()
      (with-unwind-protection
          (lambda (why)
            (add-result 'cleanup))
        (lambda ()
          (add-result 'thunk-in)
          (begin0
              (raise-continuable 1)
            (add-result 'thunk-out)))))))
⇒ (3 (thunk-in exception-handler thunk-out cleanup))