[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Rescu all errors and then case statement

Misiek Sz

1/10/2008 4:17:00 PM

How can I read what type of error occured in rescue clause.
For example, I have the following:

begin
"some code here"


rescue
case
when "error type 1"

when "error type 2"
end

end

I know I could raise errors within code section and then have specif
rescues, but I want to have one rescue and then do different things with
it in the rescue.

Thanks in advance.
--
Posted via http://www.ruby-....

5 Answers

Bira

1/10/2008 4:23:00 PM

0

On Jan 10, 2008 2:17 PM, Michal Sza <nicpon@nicpon.net> wrote:
> How can I read what type of error occured in rescue clause.
> For example, I have the following:
>
> begin
> "some code here"
>
>
> rescue
> case
> when "error type 1"
>
> when "error type 2"
> end
>
> end
>
> I know I could raise errors within code section and then have specif
> rescues, but I want to have one rescue and then do different things with
> it in the rescue.
>
> Thanks in advance.

You can do something like this:

begin
...
rescue => e
<do whatever you want with e here>
end

basically, the "=> e" bit will store the thrown error in the "e" variable.


--
Bira
http://compexplicita.bl...
http://sinfoniaferida.bl...

Misiek Sz

1/10/2008 6:12:00 PM

0


that works good. In addition to that is there a way to tell what error
type is it ?
--
Posted via http://www.ruby-....

Radoslaw Bulat

1/10/2008 8:12:00 PM

0

T24gSmFuIDEwLCAyMDA4IDU6MTcgUE0sIE1pY2hhbCBTemEgPG5pY3BvbkBuaWNwb24ubmV0PiB3
cm90ZToKPiBIb3cgY2FuIEkgcmVhZCB3aGF0IHR5cGUgb2YgZXJyb3Igb2NjdXJlZCBpbiByZXNj
dWUgY2xhdXNlLgo+IEZvciBleGFtcGxlLCBJIGhhdmUgdGhlIGZvbGxvd2luZzoKPgo+IGJlZ2lu
Cj4gICAic29tZSBjb2RlIGhlcmUiCj4KPgo+IHJlc2N1ZQo+ICAgY2FzZQo+ICAgIHdoZW4gImVy
cm9yIHR5cGUgMSIKPgo+ICAgIHdoZW4gImVycm9yIHR5cGUgMiIKPiAgIGVuZAo+Cj4gZW5kCj4K
PiBJIGtub3cgSSBjb3VsZCByYWlzZSBlcnJvcnMgd2l0aGluIGNvZGUgc2VjdGlvbiBhbmQgdGhl
biBoYXZlIHNwZWNpZgo+IHJlc2N1ZXMsIGJ1dCBJIHdhbnQgdG8gaGF2ZSBvbmUgcmVzY3VlIGFu
ZCB0aGVuIGRvIGRpZmZlcmVudCB0aGluZ3Mgd2l0aAo+IGl0IGluIHRoZSByZXNjdWUuCgoKZXJy
b3JzID0gW0lPRXJyb3IsIFplcm9EaXZpc2lvbkVycm9yLCBBcmd1bWVudEVycm9yXQoKZXJyb3Jz
LmVhY2ggZG8gfGtsYXNzfAogIGJlZ2luCiAgICBwdXRzICJyYWlzaW5nICN7a2xhc3MubmFtZX0i
CiAgICByYWlzZSBrbGFzcwogIHJlc2N1ZSA9PiBlCiAgICBjYXNlIGUKICAgIHdoZW4gSU9FcnJv
cgogICAgICBwdXRzICJpdCdzIElPRXJyb3IhIgogICAgd2hlbiBaZXJvRGl2aXNpb25FcnJvcgog
ICAgICBwdXRzICJpdCdzIFplcm9EaXZpc2lvbkVycm9yIgogICAgZWxzZQogICAgICBwdXRzICJv
dGhlciBlcnJvcjogI3tlLmNsYXNzLm5hbWV9IgogICAgZW5kCiAgZW5kCmVuZAoKCi0tIApSYWRv
c7NhdyBCdbNhdAoKaHR0cDovL3JhZGFyZWsuam9nZ2VyLnBsIC0gbfNqIGJsb2cK

Daniel Finnie

1/10/2008 8:17:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

e.class

Dan


On 1/10/08, Michal Sza <nicpon@nicpon.net> wrote:
>
>
> that works good. In addition to that is there a way to tell what error
> type is it ?
> --
> Posted via http://www.ruby-....
>
>

Misiek Sz

1/10/2008 8:37:00 PM

0

Daniel Finnie wrote:
> e.class
>
> Dan
Thanks guys.

--
Posted via http://www.ruby-....