If I have a loop, and somewhere in the loop, I get an exception or error. How do I keep the loop going?
Foos.each do |foo|
....
# Random error/exception thrown here
....
end
Should I have a rescue block in the loop? Will that make the loop finish? Or is there a better alternative?
You can use add a
begin/rescueblock. I am not sure there is other ways to do keep loop going if an error is raised.Since your title in the other hand ask for a way to ends the loop.
If you want the loop to ends in the
rescue, you can usebreak.