Created
January 3, 2022 22:19
-
-
Save henare/3f02c7925fce8830f4c5ab438d047f8b to your computer and use it in GitHub Desktop.
Ruby rescue with 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
def rescue_with_retry(error_class: StandardError, retry_count: 3, &block) | |
attempts ||= 0 | |
yield | |
rescue error_class | |
attempts += 1 | |
puts "#{attempts}: Oh take me in your arms" | |
retry if attempts < retry_count | |
end | |
rescue_with_retry(retry_count: 5) do | |
puts "Rescue me" | |
raise | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment