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


6.9.6 Raising exceptions from the unwind handler

When a thunk raises an exception and the current exception handler raises another exception: the original exception is dropped if no specific action is taken. This is a common problem. The following example shows the mechanism.

(import (vicare))

(call/cc
    (lambda (escape)
      (with-exception-handler
          escape
        (lambda ()
          (with-exception-handler
              (lambda (E)
                (raise 2))
            (lambda ()
              (raise 1)))))))
⇒ 2

What happens if ?unwind-handler raises an exception? It was decided that such exceptions are to be blocked and discarded; ?unwind-handler procedures have to take care of themselves, handling their own errors. The following example shows the mechanism.

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

(with-result
  (guard (E (else
             (add-result 'guard-else)
             E))
    (with-unwind-protection
        (lambda (why)
          (add-result 'cleanup-in)
          (raise 2)
          (add-result 'cleanup-out))
      (lambda ()
        (add-result 'thunk-in)
        (raise 1)
        (add-result 'thunk-out)))))
⇒ (1 (thunk-in cleanup-in guard-else))