Skip to content

Instantly share code, notes, and snippets.

@bkerley
Created October 11, 2014 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bkerley/036eeccb0a5fd30867e8 to your computer and use it in GitHub Desktop.
Save bkerley/036eeccb0a5fd30867e8 to your computer and use it in GitHub Desktop.
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