Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why doesn't rescue catch Exception by default?

Reply
Thread Tools

Why doesn't rescue catch Exception by default?

 
 
Seth
Guest
Posts: n/a
 
      06-22-2007
From:
http://www.rubycentral.com/book/tut_exceptions.html

--- BEGIN
When you need to raise an exception, you can use one of the built-in
Exception classes, or you can create one of your own. If you create your
own, you might want to make it a subclass of StandardError or one of its
children. If you don't, your exception won't be caught by default.
--- END

My question is *why* doesn't it handle the most generalized class,
Exception, by default? What's the logic behind this?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      06-22-2007
On Jun 21, 2007, at 21:04, Seth wrote:

> From:
> http://www.rubycentral.com/book/tut_exceptions.html
>
> --- BEGIN
> When you need to raise an exception, you can use one of the built-in
> Exception classes, or you can create one of your own. If you create
> your
> own, you might want to make it a subclass of StandardError or one
> of its
> children. If you don't, your exception won't be caught by default.
> --- END
>
> My question is *why* doesn't it handle the most generalized class,
> Exception, by default? What's the logic behind this?


From http://www.zenspider.com/Languages/R...ckRef.html#34:

Exception
NoMemoryError
ScriptError
LoadError
NotImplementedError
SyntaxError
SignalException
Interrupt
StandardError (default for rescue)
[...]
SystemExit
fatal

You don't want to rescue any of these other exceptions (besides
StandardError and friends) unless you really know what you're doing.

Don't create your own exception classes by subclassing Exception
directly, subclass the closest matching exception class, or subclass
RuntimeError or StandardError.

--
Poor workers blame their tools. Good workers build better tools. The
best
workers get their tools to do the work for them. -- Syndicate Wars



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catch doesn't catch a thrown exception Marteno Rodia Java 5 08-05-2009 03:30 AM
How to catch and rescue a login error through telnet Prasad Pednekar Ruby 3 01-16-2008 05:42 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
(Simple?) Why is my rescue clause not catching an exception? Wes Gamble Ruby 1 11-20-2006 05:43 PM
why catch (...) can not catch such exception John Black C++ 8 08-20-2004 02:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57