Skip to content

Instantly share code, notes, and snippets.

@JonathonMA
Created September 18, 2013 06:41
Show Gist options
  • Select an option

  • Save JonathonMA/6605358 to your computer and use it in GitHub Desktop.

Select an option

Save JonathonMA/6605358 to your computer and use it in GitHub Desktop.
Errors, how do they work?
begin
fail NoMethodError, "foo"
rescue StandardError => e
puts "NoMethodError is rescued by StandardError: #{e.inspect}"
rescue NoMethodError => e
puts "NoMethodError is not rescued by StandardError: #{e.inspect}"
p e
end
puts "NoMethodError is not a StandardError" unless NoMethodError.is_a? StandardError
puts "StandardError is an ancestor of NoMethodError" if NoMethodError.ancestors.include? StandardError
__END__
NoMethodError is rescued by StandardError: #<NoMethodError: foo>
NoMethodError is not a StandardError
StandardError is an ancestor of NoMethodError
@JonathonMA

Copy link
Copy Markdown
Author

Code should have been:

puts "NoMethodError is not a StandardError" unless NoMethodError.new.is_a? StandardError

String is not a String, "string" is a String!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment