Skip to content

Instantly share code, notes, and snippets.

@duelinmarkers
Last active May 3, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duelinmarkers/2cdc2e0353b33eaceec53ad9831a21d4 to your computer and use it in GitHub Desktop.
Save duelinmarkers/2cdc2e0353b33eaceec53ad9831a21d4 to your computer and use it in GitHub Desktop.
Ruby doesn't reset rescued error var on retry
failures = 0
begin
raise "failed with failures: #{failures}" if failures < 3
puts "did not fail"
rescue => e
puts "rescued #{e}"
failures += 1
retry if failures < 5
raise "re-raising"
ensure
puts "ensure: failures: #{failures}, e: #{e}"
end
% ruby error_reset.rb
rescued failed with failures: 0
rescued failed with failures: 1
rescued failed with failures: 2
did not fail
ensure: failures: 3, e: failed with failures: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment