begin
#some routine
rescue
retry
#on third retry, output "no dice!"
end
I want to make it so that on the "third" retry, print a message.
Possibly not the best solution, but a simple way is just to make a tries
variable.
tries = 0
begin
# some routine
rescue
tries += 1
retry if tries <= 3
puts "no dice!"
end
loop do |i|
begin
do_stuff
break
rescue
raise if i == 2
end
end
or
k = 0
begin
do_stuff
rescue
k += 1
k < 3 ? retry : raise
end
begin
#your code
rescue
retry if (_r = (_r || 0) + 1) and _r < 4 # Needs parenthesis for the assignment
raise
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With