From: Robert Klemme Date: 2007-03-30T17:00:06+09:00 Subject: Re: Exceptions occassionally lost by child threads On 30.03.2007 09:19, Sylvain Joyeux wrote: >> Should exceptions automatically propagate from children up to the >> parent? And if so, why should the positioning of something as innocuous >> as sleep 1 matter? > Because you have a timeout on the join (a.join(1)) > > In the first case it sleeps one second, and waits for 'a' to finish. It > works if 'a' raises within two seconds. Note that it could also fail > since 'sleep' is not perfect and it is possible for the main thread to > reach the timeout on 'join' before 'a' raises. > > In the second case, the main thread only waits 'a' for one second. It is > useless because of the sleep(2) in 'a'. > > It should work as expected if you replace a.join(1) by a.join It seems to be a property of Thread#join and #value that they will automatically propagate any uncaught exceptions of the the joined thread: irb(main):003:0> t=Thread.new { sleep 20; raise "Foo" } => # irb(main):004:0> begin; t.join; rescue Exception => e; p e; end # => nil I think this behavior is documented, although a bit cryptic IMHO: "If thr had previously raised an exception and the abort_on_exception and $DEBUG flags are not set (so the exception has not yet been processed) it will be processed at this time." http://www.ruby-doc.org/core/classes/Thread.html#M000474 Kind regards robert