Created
March 21, 2012 13:35
-
-
Save Rafe/2146914 to your computer and use it in GitHub Desktop.
Ruby Exception Handling cheatsheet
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 | |
#do something... | |
raise Exception, "Error message" | |
raise ArgumentError | |
rescue Exception => e | |
puts e.message | |
rescue ArgumentError => e | |
puts e.message | |
ensure | |
end | |
#Exceptions | |
Exception | |
NoMemoryError | |
ScriptError | |
LoadError | |
NotImplementedError | |
SyntaxError | |
SignalException | |
Interrupt | |
StandardError | |
ArgumentError | |
IOError | |
EOFError | |
IndexError | |
LocalJumpError | |
NameError | |
NoMethodError | |
RangeError | |
FloatDomainError | |
RegexpError | |
RuntimeError | |
SecurityError | |
SystemCallError | |
SystemStackError | |
ThreadError | |
TypeError | |
ZeroDivisionError | |
SystemExit | |
fatal | |
#catch | |
message = catch(:error) do | |
throw :error, "error" | |
end | |
#=> "error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment