From: Kent Dahl Date: 2003-07-30T11:04:13+09:00 Subject: Re: How to rescue any exception in 1.8? 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. Rescue without an Exception type only catches StandardError and subclasses. The inheritance hierarchy of exceptions are one of the changes between 1.6 and 1.8, IIRC... [kentda@v052a kentda]$ ruby -v -e "require 'timeout';p TimeoutError.ancestors" ruby 1.6.8 (2002-12-24) [i386-linux-gnu] [TimeoutError, StandardError, Exception, Object, Kernel] [kentda@v052a kentda]$ /usr/local/bin/ruby -v -e "require 'timeout';p TimeoutError.ancestors" ruby 1.8.0 (2003-07-24) [i686-linux] [Timeout::Error, Interrupt, SignalException, Exception, Object, Kernel] HTH -- (\[ Kent Dahl ]/)_ _~_ _____[ http://www.pvv.org/~kentda/ ]_____/~ ))\_student_/(( \__d L b__/ (pre-) Master of Science in Technology ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)