Created
September 18, 2013 06:41
-
-
Save JonathonMA/6605358 to your computer and use it in GitHub Desktop.
Errors, how do they work?
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
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code should have been:
Stringis not aString,"string"is aString!