Ask a Question related to Ruby, Design and Development.
-
Simon Kitching #1
exceptions
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??
Thanks,
Simon
Simon Kitching Guest
-
ANNOUNCE: POE v0.33 - Now with exceptions.
-------------------------------------- Happy New Gregorian Year! In advance! -------------------------------------- POE 0.33 has been released.... -
WebServices exceptions
I just want to check my facts. I've heard some differing accounts, but my understanding of an article I read on the MSDN site is, if you throw an... -
Custom Exceptions
I'm creating a Web service and a Windows Forms application to consume it. My question is about throwing a custom exception inside the WebService.... -
Propagating exceptions or not
Hi, I just wonder what people consider to be the best approach when it comes to propagating exceptions that has occurred in a web-service (or in... -
[PHP-DEV] exceptions question
You should not use exceptions for program logic. Exceptions are use to handle exceptional cases and the overhead of handling an exception may be... -
Ryan Pavlik #2
Re: exceptions
On Tue, 4 Nov 2003 08:49:48 +0900
Simon Kitching <simon@ecnetwork.co.nz> wrote:
Yes, just subclass Exception and treat it like a normal class (since> 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??
it is a normal class). I use this as some evil magic to implement a
few things.
--
Ryan Pavlik <rpav@mephle.com>
"Yeah, I mean what're the odds of those two brain cells bumping into
each other admist all that emptiness?" - 8BT
Ryan Pavlik Guest
-
Joel VanderWerf #3
Re: exceptions
Simon Kitching wrote:
Yep:> 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??
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
Joel VanderWerf Guest
-
Ara.T.Howard #4
Re: exceptions
On Tue, 4 Nov 2003, Simon Kitching wrote:
something like this?> 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??
irb(main):001:0> class MyException < Exception; def method(arg); @arg = arg; end; end
=> nil
irb(main):002:0> e = MyException.new 'foo bar baz'
=> #<MyException: foo bar baz>
irb(main):003:0> e.method 42
=> nil
irb(main):004:0> raise e
(irb):4:in `irb_binding': foo bar baz (MyException)
from /data/ruby-1.8.0//lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
from /data/ruby-1.8.0//lib/ruby/1.8/irb/workspace.rb:52
-a
--
ATTN: please update your address books with address below!
================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: [url]http://www.ngdc.noaa.gov/stp/[/url]
| NGDC :: [url]http://www.ngdc.noaa.gov/[/url]
| NESDIS :: [url]http://www.nesdis.noaa.gov/[/url]
| NOAA :: [url]http://www.noaa.gov/[/url]
| US DOC :: [url]http://www.commerce.gov/[/url]
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
================================================== =============================
Ara.T.Howard Guest
-
Simon Kitching #5
Re: exceptions
On Tue, 2003-11-04 at 12:58, Joel VanderWerf wrote:
Hah! the raise operator (presumably a method in Kernel?) can take an> e = MyException.new("foo", "bar", "baz")
> e.doSomething
> e.setWidget("widget")
> raise e
>
Object as its first parameter. Cool.
That wasn't mentioned in the Pragmatic Programmer's book (at least not
that I saw). Maybe I should have guessed that is how it worked..
Thanks
Simon
Simon Kitching Guest
-
Nikolai Weibull #6
Re: exceptions
* Simon Kitching <simon@ecnetwork.co.nz> [Nov, 04 2003 10:40]:
yes it is,> That wasn't mentioned in the Pragmatic Programmer's book ...
nikolai
--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: [url]www.pcppopper.org[/url] :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
Nikolai Weibull Guest



Reply With Quote

