[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Accessing the last error raised outside of a rescue block

Doug Livesey

7/18/2008 9:19:00 AM

Hi -- I want to be able to grab some details from an error, but not just
the message.
So I want a variable called result to be either the result of a method,
or a property of the error raised by that method.
If the property I wanted from the error was the message, then I could do
this like this:
result = my_method rescue $!

However, what I want to do is call a method on the error, like so:
result = my_method rescue last_error.my_other_method

Where last_error is the mysterious means I employ to get at the error
raised, and my_other_method is what I want to call on it.

Does anyone know if this is possible?
Cheers,
Doug.
--
Posted via http://www.ruby-....

2 Answers

Phlip

7/18/2008 10:47:00 AM

0

Doug Livesey wrote:

> result = my_method rescue $!
>
> However, what I want to do is call a method on the error, like so:
> result = my_method rescue last_error.my_other_method
>
> Where last_error is the mysterious means I employ to get at the error
> raised, and my_other_method is what I want to call on it.

The last time I tried to do anything with a rescue statement modifier other than
replace its statements value, it didn't work. However...

result = my_method rescue $!.my_other_method

Does that work?

--
Phlip

Doug Livesey

7/18/2008 1:11:00 PM

0

Yup, that worked beautifully, cheers!
Now the scary question is "why on earth didn't I try that?"
I've whittled it down to two possible answers, and the good news for you
is that you are a genius, because the alternative is that I'm a maroon,
and I'm not having that.
Cheers, man!
Doug.
--
Posted via http://www.ruby-....