[plt-scheme] Chaining exception handlers between threads

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Feb 25 12:13:36 EST 2008

It is probably easiest to propogate the exceptions yourself:

(thread (lambda () (with-handlers ((exn? (lambda (e) (channel-put
exn-chan e)))) ...whatever you were going to do...)))

and then have the main thread wait on the exn-chan.

If the main thread was doing useful separately from the other threads,
and you want to interrupt it somehow, I'd suggest not doing that, but
instead moving that work to a new child thread, but you may have other
reasons that that won't work, so a few more details might help.


On Mon, Feb 25, 2008 at 11:05 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> Hello,
>  I want to install an exception handler around a number of threads (so
>  a simple use of call-in-nested-thread will not work).  More precisely,
>  I want any exception in my threads to kill all the threads and then
>  raise an exception in the parent thread.  I'm not sure how to
>  propagate the exn from the child thread to the parent.  The obvious
>  solution doesn't work:
>  > (with-handlers ([exn? (lambda (e) (display "got it!"))]) (thread (lambda () (error "died"))))
>  #<thread>
>  > died
>  Do I have to write the communication by hand?
>  I think this bit of information has fallen through the gaps in
>  documenting threads, exception, and parameters -- but I'm happy to be
>  pointed to the page that proves me wrong!
>  N.
>  _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.