[Scheme-reports] 6.1 Exceptions needs examples
cowan at mercury.ccil.org
Tue Mar 20 23:28:43 EDT 2012
Per Bothner scripsit:
> In an implementation like Kawa without full call/cc support
> it should still be possible to support "normal" non-continuable
> exception handling, hopefully in a way that makes use of and
> integrates with native JVM exceptions.
I've been thinking about this off and on for some time. Here are my
First, a `parameterize` expression has to compile to a try-finally so that
when the thunk terminates, the parameter will be reset.
A hidden stack (Java or Scheme, doesn't matter) needs to exist which
holds the handlers. A `with-exception-handler` call pushes the handler
itself on the stack, whereas a `guard` expression just pushes a marker
of some sort. Again, a try-finally is needed to clean up the stack as
control exits through it.
On a call to either `raise` or `raise-continuable` the stack is popped.
If it's a procedure object, apply it to the condition object passed.
If that returns, either re-raise or return to the caller as the case
may be. But if the object on the stack was a marker, wrap the condition
object in a Java RuntimeException and throw it. A `guard` expression is
compiled into a try-catch structure, so it will intercept it. Likewise,
`with-exception-handler` catches any RuntimeException and invokes the
thunk on it.
I hope this makes sense.
John Cowan cowan at ccil.org http://ccil.org/~cowan
Sound change operates regularly to produce irregularities;
analogy operates irregularly to produce regularities.
--E.H. Sturtevant, ca. 1945, probably at Yale
More information about the Scheme-reports