Retry A Block After An Exception
begin
puts "About to do a thing (#{retries})"
raise StandardError if rand(5) != 4
puts "Success!"
rescue StandardError => e
retry
endbegin
retries ||= 0
puts "About to do a thing (#{retries})"
raise StandardError if rand(5) != 4
puts "Success!"
rescue StandardError => e
retry if (retries += 1) < 3
# all retries failed, re-raise exception
raise e
endLast updated