Skip to content

Instantly share code, notes, and snippets.

@albertoleal
Created May 24, 2011 00:35
Show Gist options
  • Save albertoleal/987933 to your computer and use it in GitHub Desktop.
Save albertoleal/987933 to your computer and use it in GitHub Desktop.
Avoid double-raised exception in Ruby
module NoDoubleRaise
def raise(*args)
if $! && args.first != $!
warn "There is already one exception #{caller.first} raised"
exit! false
else
super
end
end
end
class Object
include NoDoubleRaise
end
begin
raise StandardError
rescue
raise RuntimeError
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment