From: Joel VanderWerf Date: 2003-11-04T08:58:20+09:00 Subject: Re: exceptions Simon Kitching wrote: > Hi, > > I'm puzzled about how to associate custom information with an Exception > class I am throwing. > > In Java, I would do this > > MyException e = new MyException("foo", "bar", "baz"); > e.doSomething(); > e.setWidget(widget); > // now e is all set up, so throw it > throw e; > > Can this sort of thing be done in Ruby?? Yep: class MyException < Exception def initialize(*args); @args = args; end def doSomething; end def setWidget(widget); @widget = widget; end end e = MyException.new("foo", "bar", "baz") e.doSomething e.setWidget("widget") raise e