[racket] continuation barrier in raise

From: Casey Klein (clklein at eecs.northwestern.edu)
Date: Wed Jan 5 12:10:52 EST 2011

On Wed, Jan 5, 2011 at 8:55 AM, Keiko Nakata <keiko at kurims.kyoto-u.ac.jp> wrote:
>> A `with-handlers' handler and a `call-with-exception-handler' handler
>> are invoked with different continuations. A `with-handlers' handler is
>> invoked with the continuation of the entire `with-handlers'
>> expression; a `call-with-exception-handler' handler is invoked with
>> the continuation of the `raise' call. In this example, the barrier is
>> gone by the time the `with-handlers' handler runs.
>
> Ah! I now have a shorter example:
>
> (call-with-exception-handler
>  (lambda (_) (control f 10))
>  (lambda () (raise 4)))
>
> Is it possible to observe this behavior
> without 'call-with-exception-handler'
> (and without other internal definitions such as 'exception-handler-key')?
> I am guessing it could be via other control operators.
>

Well, you can configure the handler for uncaught exceptions to capture
and expose the continuation with the barrier.

(define t (make-continuation-prompt-tag))

(call-with-continuation-prompt
 (λ ()
   (parameterize ([uncaught-exception-handler
                   (λ (_)
                     (call-with-current-continuation
                      (λ (k) (abort-current-continuation t k))
                      t))])
     (call-with-continuation-prompt
      (λ () (raise 3)))))
 t
 (λ (k)
   (call-with-continuation-prompt
    (λ () (k 4))
    t)))

But that's not really so different from using
`call-with-exception-handlers' directly.

I think that any method of observing the barrier boils down to some
similar way of installing an exception handler.

>> I only discovered this subtlety myself about a week ago,
>
> Indeed 'call-with-exception-handler' does not appear a very common
> construct in the sense that I do not find it in OCaml or Java.
> But it looks handy.
>
> Thanks,
> Keiko
>
>


Posted on the users mailing list.