From: Robert Klemme Date: 2012-10-23T16:42:29+09:00 Subject: Re: Exception handelling in ruby On Tue, Oct 23, 2012 at 8:10 AM, ajay paswan wrote: >> something like the below would catch errors 1 and 2 respectively, and if >> the error didn't fall into those categories then the third rescue would >> catch it. >> >> rescue 1 >> rescue 2 >> rescue > > but I have seen that in the following two statements > > rescue => e > and > rescue Exception => e > > The 'execution expired' error is caught by second statement, but not > first statement.. WHY? We cannot know the type of exception if you do not post it. One possible explanation: irb(main):031:0> begin irb(main):032:1* raise 'execution expired' irb(main):033:1> rescue => e irb(main):034:1> printf "empty: %p\n", e irb(main):035:1> rescue Exceptin => e irb(main):036:1> printf "Exception: %p\n", e irb(main):037:1> end empty: # => nil irb(main):038:0> p RuntimeError.ancestors [RuntimeError, StandardError, Exception, Object, PP::ObjectMixin, Kernel, BasicObject] => [RuntimeError, StandardError, Exception, Object, PP::ObjectMixin, Kernel, BasicObject] irb(main):039:0> Note that a rescue clause causes all exceptions of the declared class *and subclasses*. Also handlers are processed from top to bottom and the first matching handler is used. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/