Exceptions with the Hanson-Lamping algorithm
The revision previously mentioned about using the Hanson-Lamping algorithm has to take exceptions into account obviously. Exception handlers registered through on-err
would reside on their own stack, the elements of which consisting of vectors with the following entries:
- The closure of the exception handler itself
- The current continuation for the call to
on-err
- The current value of the here stack (TCH) of the current thread
Exceptions are raised by checking the top of the exception handler stack. If it is empty, the default exception handling behavior is executed. Otherwise, the top stack entry is obtained, and the following occurs:
- The TCH is rerooted to the saved value of the TCH preserved when the exception handler was created
- The functions thus obtained are executed, so all functions registered by intervening
protect
ordynamic-wind
invocations get executed. - The exception handler is removed from the top of the stack.
- The saved continuation (which was the continuation created by the call to
on-err
) becomes the current continuation. - The exception handler is executed, with the exception that was raised as its argument
It seems that reference Arc handles the case of a protect clause raising its own error by catching the exception thus thrown, so the original exception is lost. That’s what this algorithm would do, if we do not remove the exception handler from the stack of exception handlers until after all the protect clauses are executed.