Last active
May 3, 2018 16:14
-
-
Save duelinmarkers/2cdc2e0353b33eaceec53ad9831a21d4 to your computer and use it in GitHub Desktop.
Ruby doesn't reset rescued error var on retry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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