Next: , Previous: , Up: unwind   [Contents][Index]


6.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.

(call/cc
    (lambda (escape)
      (with-exception-handler
          escape
        (lambda ()
          (with-exception-handler
              (lambda (E)
                (raise 2))
            (lambda ()
              (raise 1)))))))
⇒ 2
;;The originally raised value 1 is lost!

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 (only (mmck checks)
        with-result
        add-result))

(with-result
  (guard (E (else
             (add-result 'guard-else)
             E))
    (with-unwind-handler
        (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))

Next: , Previous: , Up: unwind   [Contents][Index]

This document describes version 0.1.0-devel.1 of MMCK Exceptional Conditions.