[plt-scheme] call-with-exception-handler inside with-handlers
At Fri, 21 Dec 2007 17:51:42 -0700, Matthew Flatt wrote:
> At Fri, 21 Dec 2007 21:29:15 +0100, "Marco Maggi" wrote:
> > why the form:
> >
> > (with-handlers (((lambda (o)
> > #t) (lambda (exn)
> > (list 'out exn))))
> > (call-with-exception-handler
> > (lambda (exn)
> > (list 'error exn))
> > (lambda ()
> > (raise 123))))
> >
> > gives me an uncaught exception "(error 123)" rather than
> > simply returning the value "(out 123)"? If the explanation
> > involves continuations, continuation marks or prompts: just
> > tell me to forget it (I don't wanna know :-).
>
> Both `with-handlers' and `call-with-exception-handler' evaluate the
> body expression/thunk in tail position with respect to setting the
> exception. So, the `call-with-exception-handler' is overwriting the
> handler installed by `with-handlers'.
Sorry for the self-reply, but after further thought, this looks like a
"security hole". It provides a way to escape from the `with-handlers'
expression that the person who wrote `with-handlers' is unlikely to
have considered.
So, this seems like a reason to take away the more primitive behavior
after all.
Matthew