Skip to content

Instantly share code, notes, and snippets.

@libc
Created April 30, 2014 12:55
Show Gist options
  • Save libc/001eb4a18e588651c2b6 to your computer and use it in GitHub Desktop.
Save libc/001eb4a18e588651c2b6 to your computer and use it in GitHub Desktop.
diff --git a/lib/diddy/helpers.rb b/lib/diddy/helpers.rb
index 1b78ecb..5def793 100644
--- a/lib/diddy/helpers.rb
+++ b/lib/diddy/helpers.rb
@@ -16,11 +16,13 @@ module Diddy
def try_with_exception(max_times, delay = 1, &block)
index = 0
result = false
+ exception = nil
while !result && index < max_times do
begin
result = yield
- rescue Exception
+ rescue Exception => e
+ exception ||= e
result = false
end
@@ -28,6 +30,7 @@ module Diddy
index += 1
end
+ raise exception if result == false && exception
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment