From: Charles Mills Date: 2004-12-21T02:22:04+09:00 Subject: Re: threads and errors nobu.nokada@softhome.net wrote: > Hi, > > At Mon, 20 Dec 2004 15:45:10 +0900, > Joel VanderWerf wrote in [ruby-talk:124079]: > > Another approach: > > > > begin > > Thread.new(Thread.current) do |th| > > begin > > raise "error" > > rescue => e > > th.raise e > > end > > end > > rescue => e > > p e > > end > > It's not predictable when the parent thread will be > interrupted. It may be after the rescue block. #### tmp.rb s/^\.// ..begin .. Thread.new(Thread.current) do |th| .. sleep 1 .. begin .. raise "error" .. rescue => e .. th.raise e .. end .. end ..rescue => e .. puts e ..end ..puts "before sleep" ..sleep 2 ..puts "after sleep" #### $ ruby tmp.rb before sleep tmp.rb:5: error (RuntimeError) from tmp.rb:2:in `initialize' from tmp.rb:2:in `new' from tmp.rb:2 ## If you comment out the 'sleep 1' line you get a much different result: ## $ ruby tmp.rb error before sleep after sleep Depending on the situation it may be necessary to keep the rest of the code the begin/rescue block. -Charlie