[plt-scheme] R6RS exception handling and dynamic extent [was: SXML for R6RS]

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Jul 11 11:14:03 EDT 2008

At Fri, 11 Jul 2008 09:49:02 -0500, "Robby Findler" wrote:
> On Fri, Jul 11, 2008 at 9:42 AM, Derick Eddington
> <derick.eddington at gmail.com> wrote:
> >> > Would it be possible to have guard just not jump out,
> >>
> >> It should jump out for the same reasons as `with-handlers', right?
> >
> > What are those reasons?  I've never known.
> One reason is that loops that involve a with-handlers won't be
> tail-recursive (unless you jump out yourself in the handler of
> course).
> Something like this:
> (define (keep-trying)
>   (with-handlers ([whatever? (lambda () ... (keep-trying))])
>     ...))

Actually, that's not a loop. It would be if you switch to
`with-handlers*', though.

The reason to jump out before running the handler is to restore the
dynamic context of the `with-handlers' or `guard' form. That is, you
have not only the continuation of the `with-handlers'/`guard' form (to
which the handler typically delivers a value), but also the same
dynamic configuration, including I/O ports and (in PLT Scheme) many
other parameters (current custodian, inspector, etc.). This makes it
work very much like `try ... catch' in Java and other languages.


Posted on the users mailing list.