On Jun 29, 2009, at 3:50 PM, Yossef M. wrote:
Maybe I’m misunderstanding the point of the ‘else’ clause, but
wouldn’t you put code that “only gets executed if none of the rescue
clauses are (i.e., there is no exception)” in the main body of what
you’re adding rescues to? (viz. begin block, method definition)
–
-yossef
If there is something that isn’t valid in the face of an exception and
for which you do not want to catch any exceptions, but must occur
prior to the ensure block.
begin
a
b
rescue => ex
c
else
d
ensure
e
end
If doing d is only valid if b completes, and assuming that (x) means
an exception happens during x, the possible sequences are:
(a),c,e
(a),©,e
a,(b),c,e
a,(b),©,e
a,b,d,e
a,b,(d),e
Note that d happens before e, but (d) does not cause the rescue clause
to be invoked.
I know that I’ve run into the practical need for this at least once
(but there were several rescue clauses, not just one). If I could
recall the specific example, I’d have put it in.
-Rob
Rob B. http://agileconsultingllc.com
[email protected]