Skip to content

Instantly share code, notes, and snippets.

@henare
Created January 3, 2022 22:19
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 henare/3f02c7925fce8830f4c5ab438d047f8b to your computer and use it in GitHub Desktop.
Save henare/3f02c7925fce8830f4c5ab438d047f8b to your computer and use it in GitHub Desktop.
Ruby rescue with retry
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