Friday, February 09, 2007

begin rescue else end

Jamis Buck points out the not open used "else" clause of the begin end block. Apparently, the begin end clause can have an else in there.

For example:

begin
# Your normal code block
rescue SomeException
# ... handling exception
else
# This part only run if the main code did not throw
# an exception.
ensure
# The very last thing to be run before the clause exit.
# Code in the ensure clause will always get execute.
end

You can read more about this at Jamis Buck blog entry, begin + else.

2 comments:

Anonymous said...

"Jamis Buck points out the not open used "else" clause". . .

I believe you mean "often".

Jus' sayin!

Anonymous said...

Nice job on rescue clause; I always forget how to write them. Thanks
--Richard