Skip to content

Instantly share code, notes, and snippets.

@Rafe
Created March 21, 2012 13:35
Show Gist options
  • Save Rafe/2146914 to your computer and use it in GitHub Desktop.
Save Rafe/2146914 to your computer and use it in GitHub Desktop.
Ruby Exception Handling cheatsheet
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