[plt-scheme] exn:break-continuation
When `with-handlers' catches an exception, it escapes to the context of
the `with-handlers' form before calling the handler. At that point,
it's too late to continue from the break exception.
To catch an `exn:break' and continue, you have to use the lower-level
`call-with-exception-handler' function:
#lang scheme
(define caught #f)
(printf "starting~n")
(define k
(let/ec esc
(call-with-exception-handler
(lambda (exn)
(if (exn:break? exn)
(if caught
(begin
(printf "exiting")
(esc (void)))
(begin
(set! caught #t)
(printf "break~n")
((exn:break-continuation exn))))
exn))
(lambda ()
(let loop () (loop))))))
At Tue, 25 May 2010 17:54:48 -0400, Eric Dobson wrote:
> I am having trouble using the continuation in a exn:break struct. I
> have a program which I think should catch the first exception,
> continue and then exit on the second one. The problem is that upon
> invoking the continuation, mzscheme says that I am trying to jump into
> an escape continuation. It seems to me that the continuation in an
> exn:break struct should not be an escape-continuation, otherwise what
> is the point of having it?
>
> #!/usr/bin/env mzscheme
> #lang scheme
>
> (define caught #f)
> (printf "starting~n")
> (define k
> (with-handlers ((exn:break? (lambda (exn)
> (if caught
> (printf "exiting")
> (begin
> (set! caught #t)
> (printf "break~n")
> ((exn:break-continuation exn)))))))
> (let loop () (loop))))
>
> -Eric
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme