From: Wayne Vucenic Date: 2005-12-09T07:55:23+09:00 Subject: Re: rescue anything raised? Hi Daniel, On 12/8/05, Daniel Schierbeck wrote: > Jeffrey Moss wrote: > > rescue Exception > > > > All exceptions descend from class Exception. > > > > -Jeff > > I actually think that's kinda non-rubyish. Why not simply require > objects to have the basic methods of an exception (`exception', and > maybe `message', `backtrace', etc.) to qualify as an exception? > > class FooException > attr_reader :message > > def initialize(message) > @message = message > end > > def exception(message = nil) > if message.nil? > return self > else > self.new(message) > end > end > end You can raise any object whose exception method returns an Exception. So your example would become: class FooException def initialize(message) @message = message end def exception Exception.new(@message) end end begin raise FooException.new("I'm a foo exception") rescue Exception => e p e end which outputs # Wayne --- Wayne Vucenic No Bugs Software "Ruby and C++ Agile Contract Programming in Silicon Valley"