Rescu all errors and then case statement

M

Michal Sza

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.
 
B

Bira

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.
 
M

Michal Sza

that works good. In addition to that is there a way to tell what error
type is it ?
 
R

Rados³aw Bu³at

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

Daniel Finnie

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

e.class

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top