Skip to content

Instantly share code, notes, and snippets.

@dskecse
Last active November 8, 2015 06:23
Show Gist options
  • Save dskecse/d0d230dd35c07a4d07a9 to your computer and use it in GitHub Desktop.
Save dskecse/d0d230dd35c07a4d07a9 to your computer and use it in GitHub Desktop.
Disallowing double-raise
require 'English'
module NoDoubleRaisable
def error_handled!
$ERROR_INFO = nil
end
def raise(*args)
if $ERROR_INFO && args.first != $ERROR_INFO
warn "Double raise at #{caller.first}, aborting."
exit! false
else
super
end
end
end
class Object
include NoDoubleRaisable
end
if $0 == __FILE__
begin
raise 'Initial failure'
rescue
# error_handled!
raise 'Secondary failure'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment