Ruby: Continue a loop after catching an exception
Posted
by Santa
on Stack Overflow
See other posts from Stack Overflow
or by Santa
Published on 2010-04-12T19:36:24Z
Indexed on
2010/04/12
19:43 UTC
Read the original article
Hit count: 346
Basically, I want to do something like this (in Python, or similar imperative languages):
for i in xrange(1, 5):
try:
do_something_that_might_raise_exceptions(i)
except:
continue # continue the loop at i = i + 1
How do I do this in Ruby? I know there are the redo
and retry
keywords, but they seem to re-execute the "try" block, instead of continuing the loop:
for i in 1..5
begin
do_something_that_might_raise_exceptions(i)
rescue
retry # do_something_* again, with same i
end
end
© Stack Overflow or respective owner