# Does "rescue" wihtour argument handle any kind of Exception or not?

**URL:** <https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812>\
**Category:** ruby-talk\
**Created:** [20 July 2008 14:34 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812 "2008-07-20T14:34:42Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inaki\_Baz\_Castillo](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Inaki\_Baz\_Castillo](https://rubytalk.org/u/Inaki_Baz_Castillo)\
**Post date:** [20 July 2008 14:34 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/1 "2008-07-20T14:34:42Z")

</div>

Hi, I read in this article:  
&nbsp;&nbsp;[http://jerith.livejournal.com/40063.html](http://jerith.livejournal.com/40063.html)  
that:

> **···**
>
> ---------------------------  
> Exception  
> &nbsp;&nbsp;- StandardError  
> &nbsp;&nbsp;&nbsp;&nbsp;- RuntimeError  
> &nbsp;&nbsp;&nbsp;&nbsp;- ZeroDivisionError  
> &nbsp;&nbsp;- ScriptError  
> &nbsp;&nbsp;&nbsp;&nbsp;- SyntaxError  
> &nbsp;&nbsp;- SystemExit  
> &nbsp;&nbsp;- SignalException  
> &nbsp;&nbsp;&nbsp;&nbsp;- Interrupt
> 
> The important bit there is that all the stuff you can reasonably expect to  
> recover from is under StandardError. Because of this, a default rescue block  
> will not catch anything that isn't a StandardError. The observant reader will  
> notice that I helpfully showed Interrupt's position in the hierarchy. The  
> observant reader will also notice that it is not a subclass of StandardError.  
> This means that you need to catch it explicitly, or it will cause a crash.  
> ---------------------------
> 
> But is it really true? I do:
> 
> ----  
> begin  
> &nbsp;&nbsp;raise Interrupt  
> rescue  
> &nbsp;&nbsp;puts "rescued !!!"  
> end  
> ----
> 
> And I get:
> 
> =\> "rescued !!!"
> 
> So is the above article tru or not?
> 
> Thanks.
> 
> --  
> Iñaki Baz Castillo

---

<div class="post-metadata">

**Author:** ![Stefano\_Crocco](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stefano\_Crocco](https://rubytalk.org/u/Stefano_Crocco)\
**Post date:** [20 July 2008 14:40 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/2 "2008-07-20T14:40:44Z")

</div>

For me, using ruby 1.8.7, patchlevel 22 on Gentoo Linux, your code works as  
the article says, that is the exception is not being caught.

Stefano

> **···**
>
> On Sunday 20 July 2008, Iñaki Baz Castillo wrote:
> 
> > Hi, I read in this article:  
> > &nbsp;&nbsp;[http://jerith.livejournal.com/40063.html](http://jerith.livejournal.com/40063.html)  
> > that:
> > 
> > ---------------------------  
> > Exception  
> > &nbsp;&nbsp;- StandardError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- RuntimeError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- ZeroDivisionError  
> > &nbsp;&nbsp;- ScriptError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- SyntaxError  
> > &nbsp;&nbsp;- SystemExit  
> > &nbsp;&nbsp;- SignalException  
> > &nbsp;&nbsp;&nbsp;&nbsp;- Interrupt
> > 
> > The important bit there is that all the stuff you can reasonably expect to  
> > recover from is under StandardError. Because of this, a default rescue  
> > block will not catch anything that isn't a StandardError. The observant  
> > reader will notice that I helpfully showed Interrupt's position in the  
> > hierarchy. The observant reader will also notice that it is not a subclass  
> > of StandardError. This means that you need to catch it explicitly, or it  
> > will cause a crash. ---------------------------
> > 
> > But is it really true? I do:
> > 
> > ----  
> > begin  
> > &nbsp;&nbsp;raise Interrupt  
> > rescue  
> > &nbsp;&nbsp;puts "rescued !!!"  
> > end  
> > ----
> > 
> > And I get:
> > 
> > =\> "rescued !!!"
> > 
> > So is the above article tru or not?
> > 
> > Thanks.

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 14:49 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/3 "2008-07-20T14:49:50Z")

</div>

Stefano Crocco wrote:

> > Exception  
> > &nbsp;&nbsp;- StandardError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- RuntimeError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- ZeroDivisionError  
> > &nbsp;&nbsp;- ScriptError  
> > &nbsp;&nbsp;&nbsp;&nbsp;- SyntaxError  
> > &nbsp;&nbsp;- SystemExit  
> > &nbsp;&nbsp;- SignalException  
> > &nbsp;&nbsp;&nbsp;&nbsp;- Interrupt

> > begin  
> > &nbsp;&nbsp;raise Interrupt  
> > rescue  
> > &nbsp;&nbsp;puts "rescued !!!"  
> > end

> For me, using ruby 1.8.7, patchlevel 22 on Gentoo Linux, your code works as the article says, that is the exception is not being caught.

Same with p22 on Ubuntu. (I think I compiled it, too.)

Run p Interrupt.ancestors, and see if you get:

&nbsp;&nbsp;[Interrupt, SignalException, Exception, Object, Kernel]

Also, put p $! into the rescue handler to see \_what\_ you rescued!

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;Phlip

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [20 July 2008 14:55 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/4 "2008-07-20T14:55:32Z")

</div>

Did you not mean "the exception was caught" instead of "not being caught" ?  
Robert

> **···**
>
> On Sun, Jul 20, 2008 at 4:49 PM, Phlip \<phlip2005@gmail.com\> wrote:
> 
> > Stefano Crocco wrote:
> > 
> > > > Exception  
> > > > - StandardError  
> > > > &nbsp;&nbsp;&nbsp;- RuntimeError  
> > > > &nbsp;&nbsp;&nbsp;- ZeroDivisionError  
> > > > - ScriptError  
> > > > &nbsp;&nbsp;&nbsp;- SyntaxError  
> > > > - SystemExit  
> > > > - SignalException  
> > > > &nbsp;&nbsp;&nbsp;- Interrupt
> > 
> > > > begin  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> > > > rescue  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> > > > end
> > 
> > > For me, using ruby 1.8.7, patchlevel 22 on Gentoo Linux, your code works  
> > > as the article says, that is the exception is not being caught.
> > 
> > Same with p22 on Ubuntu. (I think I compiled it, too.)
> > 
> > Run p Interrupt.ancestors, and see if you get:
> > 
> > [Interrupt, SignalException, Exception, Object, Kernel]
> > 
> > Also, put p $! into the rescue handler to see \_what\_ you rescued!
> > 
> > --  
> > Phlip

---

<div class="post-metadata">

**Author:** ![Inaki\_Baz\_Castillo](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Inaki\_Baz\_Castillo](https://rubytalk.org/u/Inaki_Baz_Castillo)\
**Post date:** [20 July 2008 15:01 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/5 "2008-07-20T15:01:03Z")

</div>

> Stefano Crocco wrote:  
> \>\> Exception  
> \>\> - StandardError  
> \>\> - RuntimeError  
> \>\> - ZeroDivisionError  
> \>\> - ScriptError  
> \>\> - SyntaxError  
> \>\> - SystemExit  
> \>\> - SignalException  
> \>\> - Interrupt  
> \>\>  
> \>\> begin  
> \>\> raise Interrupt  
> \>\> rescue  
> \>\> puts "rescued !!!"  
> \>\> end  
> \>  
> \> For me, using ruby 1.8.7, patchlevel 22 on Gentoo Linux, your code works  
> \> as the article says, that is the exception is not being caught.
> 
> Same with p22 on Ubuntu. (I think I compiled it, too.)
> 
> Run p Interrupt.ancestors, and see if you get:
> 
> &nbsp;&nbsp;[Interrupt, SignalException, Exception, Object, Kernel]

ruby1.8 1.8.6.36-1ubuntu3.1

> p Interrupt.ancestors

[Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
PP::ObjectMixin, Kernel]

It's different!

> **···**
>
> El Domingo, 20 de Julio de 2008, Phlip escribió:
> 
> > Also, put p $! into the rescue handler to see \_what\_ you rescued!
> 
> -----------  
> require 'timeout'
> 
> begin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> rescue  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts $!  
> end  
> ----------
> 
> ~# ./test.rb  
> rescued !!!  
> wrong number of arguments (0 for 1)
> 
> ¿?
> 
> --  
> Iñaki Baz Castillo

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 15:04 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/6 "2008-07-20T15:04:44Z")

</div>

> > > > begin  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> > > > rescue  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> > > > end

> Did you not mean "the exception was caught" instead of "not being caught" ?  
> Robert

On Ubuntu, with p22, the Interrupt was not rescued, and it blew my program away.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black1](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@David\_A\_Black1](https://rubytalk.org/u/David_A_Black1)\
**Post date:** [20 July 2008 15:04 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/7 "2008-07-20T15:04:55Z")

</div>

Hi --

> > Stefano Crocco wrote:
> > 
> > > > Exception  
> > > > &nbsp;&nbsp;- StandardError  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;- RuntimeError  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;- ZeroDivisionError  
> > > > &nbsp;&nbsp;- ScriptError  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;- SyntaxError  
> > > > &nbsp;&nbsp;- SystemExit  
> > > > &nbsp;&nbsp;- SignalException  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;- Interrupt
> > > > 
> > > > begin  
> > > > &nbsp;&nbsp;raise Interrupt  
> > > > rescue  
> > > > &nbsp;&nbsp;puts "rescued !!!"  
> > > > end
> > > 
> > > For me, using ruby 1.8.7, patchlevel 22 on Gentoo Linux, your code works  
> > > as the article says, that is the exception is not being caught.
> > 
> > Same with p22 on Ubuntu. (I think I compiled it, too.)
> > 
> > Run p Interrupt.ancestors, and see if you get:
> > 
> > &nbsp;&nbsp;[Interrupt, SignalException, Exception, Object, Kernel]
> 
> ruby1.8 1.8.6.36-1ubuntu3.1
> 
> \> p Interrupt.ancestors  
> [Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
> PP::ObjectMixin, Kernel]
> 
> It's different!
> 
> > Also, put p $! into the rescue handler to see \_what\_ you rescued!
> 
> -----------  
> require 'timeout'
> 
> begin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> rescue  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts $!  
> end  
> ----------
> 
> ~# ./test.rb  
> rescued !!!  
> wrong number of arguments (0 for 1)
> 
> ¿?

begin  
&nbsp;&nbsp;&nbsp;raise Interrupt  
rescue =\> e  
&nbsp;&nbsp;&nbsp;puts "rescued !!!: #{e.class}"  
end

It's ArgumentError in 1.8.6, and nothing (the rescue doesn't happen)  
in 1.9.

David

> **···**
>
> On Mon, 21 Jul 2008, Iñaki Baz Castillo wrote:
> 
> > El Domingo, 20 de Julio de 2008, Phlip escribió:
> 
> --  
> Rails training from David A. Black and Ruby Power and Light:  
> &nbsp;&nbsp;&nbsp;Intro to Ruby on Rails July 21-24 Edison, NJ  
> &nbsp;&nbsp;&nbsp;Advancing With Rails August 18-21 Edison, NJ  
> See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![Stefano\_Crocco](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stefano\_Crocco](https://rubytalk.org/u/Stefano_Crocco)\
**Post date:** [20 July 2008 15:09 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/8 "2008-07-20T15:09:02Z")

</div>

The two extra ancestors come from files you most likely auto-load when irb  
starts up, namely wirble.rb and pp.rb

Stefano

> **···**
>
> On Sunday 20 July 2008, Iñaki Baz Castillo wrote:
> 
> > \> Run p Interrupt.ancestors, and see if you get:  
> > \>  
> > \> [Interrupt, SignalException, Exception, Object, Kernel]
> > 
> > ruby1.8 1.8.6.36-1ubuntu3.1
> > 
> > \> p Interrupt.ancestors  
> > [Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
> > PP::ObjectMixin, Kernel]
> > 
> > It's different!

---

<div class="post-metadata">

**Author:** ![\_Trys](https://avatars.discourse-cdn.com/v4/letter/_/8e8cbc/32.png) [@\_Trys](https://rubytalk.org/u/_Trys)\
**Post date:** [20 July 2008 16:34 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/9 "2008-07-20T16:34:48Z")

</div>

Iñaki Baz Castillo wrote:

> > Run p Interrupt.ancestors, and see if you get:
> > 
> > &nbsp;&nbsp;&nbsp;[Interrupt, SignalException, Exception, Object, Kernel]
> 
> ruby1.8 1.8.6.36-1ubuntu3.1
> 
> \> p Interrupt.ancestors  
> [Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
> PP::ObjectMixin, Kernel]
> 
> It's different!
> 
> > Also, put p $! into the rescue handler to see \_what\_ you rescued!
> 
> -----------  
> require 'timeout'
> 
> begin  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> rescue  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts $!  
> end  
> ----------
> 
> ~# ./test.rb  
> rescued !!!  
> wrong number of arguments (0 for 1)

Right here is your problem, same thing is happening to me (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]) For certain reasons raise throws ArgumentError (which then gets caught by single rescue) for Interrupt without additional parameters.

This will probably work if you just need to raise Interrupt:

raise Interrupt, "an exception"

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 15:29 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/10 "2008-07-20T15:29:46Z")

</div>

Stefano Crocco wrote:

> > \> p Interrupt.ancestors  
> > [Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
> > PP::ObjectMixin, Kernel]

> > It's different!

It's the same! StandardError is not on the list.

> The two extra ancestors come from files you most likely auto-load when irb starts up, namely wirble.rb and pp.rb

\<voice impersonation='Homer Simpson'\>  
&nbsp;&nbsp;&nbsp;Stupid polymorphic mixins!  
\</voice\>

Gotta do this:

&nbsp;&nbsp;&nbsp;rescue  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p $1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p $1.message  
&nbsp;&nbsp;&nbsp;end

You might be rescuing something else.

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;Phlip

---

<div class="post-metadata">

**Author:** ![Inaki\_Baz\_Castillo](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Inaki\_Baz\_Castillo](https://rubytalk.org/u/Inaki_Baz_Castillo)\
**Post date:** [20 July 2008 15:41 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/11 "2008-07-20T15:41:55Z")

</div>

Yes, you are right.

> **···**
>
> El Domingo, 20 de Julio de 2008, Stefano Crocco escribió:
> 
> > \> \> p Interrupt.ancestors  
> > \> [Interrupt, SignalException, Exception, Object, Wirble::Shortcuts,  
> > \> PP::ObjectMixin, Kernel]  
> > \>  
> > \>  
> > \> It's different!
> > 
> > The two extra ancestors come from files you most likely auto-load when irb  
> > starts up, namely wirble.rb and pp.rb
> 
> --  
> Iñaki Baz Castillo

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [20 July 2008 17:31 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/12 "2008-07-20T17:31:19Z")

</div>

Did you expect your program to do anything after printing "rescued !!!" ?  
R.

> **···**
>
> On Sun, Jul 20, 2008 at 5:04 PM, Phlip \<phlip2005@gmail.com\> wrote:
> 
> > > > > > begin  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise Interrupt  
> > > > > > rescue  
> > > > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "rescued !!!"  
> > > > > > end
> > 
> > > Did you not mean "the exception was caught" instead of "not being caught"  
> > > ?  
> > > Robert
> > 
> > On Ubuntu, with p22, the Interrupt was not rescued, and it blew my program  
> > away.
> 
> --  
> [http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)
> 
> ---  
> AALST (n.) One who changes his name to be further to the front  
> D.Adams; The Meaning of LIFF

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 15:34 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/13 "2008-07-20T15:34:51Z")

</div>

> Gotta do this:

&nbsp;&nbsp;&nbsp;rescue  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p $!  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p $!.message  
&nbsp;&nbsp;&nbsp;&nbsp;end

> You might be rescuing something else.

D'oh!

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 17:59 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/14 "2008-07-20T17:59:43Z")

</div>

> Did you expect your program to do anything after printing "rescued !!!" ?

Assuming you are addressing a senior enjinere, not a neophyte, yes I could tell the difference between an interrupt and the rest of my program running. It has major side-effects; I stuck the sample code at the top of my current project.

Curiously, this is what the original code was doing:

begin  
&nbsp;&nbsp;&nbsp;raise Interrupt  
rescue Object  
&nbsp;&nbsp;&nbsp;p $!.class # sez Interrupt  
end

I didn't catch it either - 'raise' raises the given object, which here was class Interrupt, and the metaclass itself of course does not inherit StandardError.

Try:

begin  
&nbsp;&nbsp;&nbsp;raise Interrupt.new('L.A. woman')  
rescue  
&nbsp;&nbsp;&nbsp;p $!.class  
end

That does not invoke the rescue, and does clobber the program, all for the correct reasons. And rescue Interrupt catches it.

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;Phlip

---

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [20 July 2008 15:39 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/15 "2008-07-20T15:39:41Z")

</div>

> You might be rescuing something else.

Also, write a little sample program. It might behave different from IRB.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black1](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@David\_A\_Black1](https://rubytalk.org/u/David_A_Black1)\
**Post date:** [20 July 2008 20:23 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/16 "2008-07-20T20:23:17Z")

</div>

Hi --

> > Did you expect your program to do anything after printing "rescued !!!" ?
> 
> Assuming you are addressing a senior enjinere, not a neophyte, yes I could tell the difference between an interrupt and the rest of my program running. It has major side-effects; I stuck the sample code at the top of my current project.
> 
> Curiously, this is what the original code was doing:
> 
> begin  
> raise Interrupt  
> rescue Object  
> p $!.class # sez Interrupt

I get ArgumentError with 1.8.6 and Interrupt with 1.9. I'm not sure  
why Interrupt needs an argument in 1.8.6.

> end
> 
> I didn't catch it either - 'raise' raises the given object, which here was class Interrupt, and the metaclass itself of course does not inherit StandardError.

raise doesn't necessarily raise the object itself. It looks for an  
'exception' method on the object:

> > obj = Object.new

=\> #\<Object:0xb1bc\>

> > def obj.exception; RuntimeError.new("Problem"); end

=\> nil

> > raise obj

RuntimeError: Problem

Instances of Exception (and subclasses) return themselves from  
#exception, so in that case you would be raising the object itself.  
The classes return new instances of themselves.

> > r = RuntimeError.exception

=\> #\<RuntimeError: RuntimeError\>

> > r.object\_id

=\> 287910

> > r.exception.object\_id

=\> 287910

If you give #exception on an instance a new message to deliver, and  
you get a new instance:

> > r.exception("Problem").object\_id

=\> 268680

David

> **···**
>
> On Mon, 21 Jul 2008, Phlip wrote:
> 
> --  
> Rails training from David A. Black and Ruby Power and Light:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intro to Ruby on Rails July 21-24 Edison, NJ  
> &nbsp;&nbsp;\* Advancing With Rails August 18-21 Edison, NJ  
> &nbsp;&nbsp;\* Co-taught by D.A. Black and Erik Kastner  
> See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [21 July 2008 10:17 UTC](https://rubytalk.org/t/does-rescue-wihtour-argument-handle-any-kind-of-exception-or-not/47812/17 "2008-07-21T10:17:34Z")

</div>

Philip you said that it was so, by confirming an output that indicated  
the contrary. As a hopeless formalist I trusted the output more than  
what you were writing in informal language, my error, I suppose.  
BTW Philip you should never assume, you know why of course ;).

Cheers  
Robert

> **···**
>
> On Sun, Jul 20, 2008 at 7:59 PM, Phlip \<phlip2005@gmail.com\> wrote:
> 
> > > Did you expect your program to do anything after printing "rescued !!!" ?
> > 
> > Assuming you are addressing a senior enjinere, not a neophyte, yes I could  
> > tell the difference between an interrupt and the rest of my program running.  
> > It has major side-effects; I stuck the sample code at the top of my current  
> > project.
> 
> --  
> [http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)
> 
> There's no one thing that's true. It's all true.  
> --  
> Ernest Hemingway
