Created
October 11, 2014 15:01
-
-
Save bkerley/036eeccb0a5fd30867e8 to your computer and use it in GitHub Desktop.
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
require 'pry' | |
module SomeRecord | |
class Base | |
def do_something | |
raise self.class::NotFoundError.new | |
end | |
def self.inherited(subclass) | |
subclass.const_set :NotFoundError, Class.new(SomeRecord::NotFoundError) | |
end | |
end | |
class NotFoundError < StandardError | |
end | |
end | |
class MyClass < SomeRecord::Base | |
def do_something | |
puts "before error" | |
super | |
rescue NotFoundError | |
puts "in rescue" | |
raise | |
end | |
end | |
class User < SomeRecord::Base | |
end | |
# binding.pry | |
begin | |
MyClass.new.do_something | |
puts "did something, shouldn't see" | |
rescue MyClass::NotFoundError | |
puts "in outer rescue" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment