From: Dossy Date: 2002-05-25T03:38:28+09:00 Subject: Re: Threading oddness On 2002.05.25, Sean Russell wrote: > > Exceptions thrown in the body of a Thread aren't handled the same way they > are elsewhere in Ruby. If an Exception occurs in a Ruby Thread and you > don't handle (rescue) it, it is silently ignored -- IE, you'll never see > the exception output. Therefore, it is /very/ important to wrap your > thread code (inside the block) with begin...rescue...end and report your > own exceptions. Perhaps Thread needs a little event handler for thread death? So, you could do something like: t = Thread.new { ... do something ... } t.on_exception { ... handle the exception here ... } The only problem is the race condition: the time between when the thread is started and when the #on_exception message gets sent to the thread. I think if you do a Thread#join on the thread that died due to an unrescued exception, you can rescue the exception there. Like this: t = Thread.new { raise } # thread dies due to unrescued RuntimeError begin t.join rescue => e p e # => RuntimeError end Maybe the work-around is to create a system where new threads get created then added to an Array, and a special single thread gets created and polls for Thread#alive? to return false then do a "begin ... Thread#join ... rescue ... end" on the dead thread to catch thread death exceptions. It's an idea I've been toying with ... -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)