Created
May 24, 2011 00:35
-
-
Save albertoleal/987933 to your computer and use it in GitHub Desktop.
Avoid double-raised exception in Ruby
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
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