From: Michael Granger Date: 2003-07-27T06:30:32+09:00 Subject: Re: How to rescue any exception in 1.8? On Saturday, Jul 26, 2003, at 13:50 US/Pacific, Philip Mak wrote: > This code will catch the exception in Ruby 1.6: > > require 'timeout' > begin > raise TimeoutError > rescue > puts "Rescued!" > end > > But in Ruby 1.8, it will not catch the exception. I found out that if > I do "rescue Exception" instead of just "rescue", it will work. > > So, my question is, if I want to rescue any exception no matter what > it is, do I have to start typing "rescue Exception" instead of > "rescue"? Yes, but that's not a change in the way rescue works: it's been like that since 1.6.x at least. For example, a begin/rescue/end under 1.6.x doesn't catch Interrupts or ScriptErrors, but does catch RuntimeErrors: $ ruby-1.6.8 -de 'begin; sleep 15; rescue => err; \ puts "Rescued #{err.class.name}"; end' Exception `Interrupt' at -e:1 - -e:1:in `sleep': Interrupt from -e:1 $ ruby-1.6.8 -de 'begin; slep 15; rescue => err; \ puts "Rescued #{err.class.name}"; end' Exception `NameError' at -e:1 - undefined method \ `slep' for # -e:1: undefined method `slep' for # (NameError) $ ruby-1.6.8 -de 'begin; raise RuntimeError, "foo!";\ rescue => err; puts "Rescued #{err.class.name}"; end' Exception `RuntimeError' at -e:1 - foo! Rescued RuntimeError -- Michael Granger Rubymage, Believer, Architect The FaerieMUD Consortium