Tom Copeland wrote:
> On Tue, 2006-11-28 at 10:07 +0900, J. B. Rainsberger wrote:
>> Being a Java programmer learning Ruby,
> 
> Welcome!  Your JUnit book rocks.
>  
>> What's the corresponding exception class in Ruby to Java's generic 
>> RuntimeException. Is it RuntimeError? StandardError? Exception? Does 
>> anyone want to tell me I'm nuts and show me a more "standard" way of 
>> designing exceptions in Ruby?
> 
> I usually rescue a generic Exception:
> 
> ===========
> $ irb
> irb(main):001:0> begin
> irb(main):002:1* raise "hey"
> irb(main):003:1> rescue Exception => e
> irb(main):004:1> puts e.class
> irb(main):005:1> end
> RuntimeError
> => nil
> ===========

Careful... that's a wide net to cast. It will catch Interrupt and 
SystemExit, for example. StandardError is often (but not always) the 
right generic class to catch.

Note that the syntax

rescue => e

(with exception class omitted) is the same as

rescue StandardError => e

This suggests that StandardError was intended to be thought of as "generic".

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407