Created
December 29, 2014 14:52
-
-
Save sstelfox/562e1a4f52fd0668dc6a to your computer and use it in GitHub Desktop.
retry_block.rb
This file contains hidden or 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 retry_block | |
| retry_count ||= 0 | |
| yield | |
| rescue => e | |
| retry_count += 1 | |
| if retry_count >= 5 | |
| puts "Fatal aborting..." | |
| raise e | |
| else | |
| puts "Error #{retry_count}: #{e.message}" | |
| retry | |
| end | |
| end | |
| retry_block do | |
| puts "Doing something..." | |
| raise "An error occurred!" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment