Skip to content

Instantly share code, notes, and snippets.

@stujo
Created October 23, 2014 16:21
Show Gist options
  • Save stujo/03656cf7cbde7ff783fc to your computer and use it in GitHub Desktop.
Save stujo/03656cf7cbde7ff783fc to your computer and use it in GitHub Desktop.
Exceptions

#Exception Handling

#Bullet Points

  • raise or fail

#Demo / Live-code Overview

  • Custom StandardError class
  • raise makes RuntimeError with argument as message
begin  
  # do our work  
rescue  => e
  # This will catch all StandardErrors and its subclasses
rescue SomeException => e  
  # Maybe do this  
rescue Exception => e
  # Maybe don't do this...
  # Are you sure you want to catch everything?
else  
  # good, no exception surfaced!  
ensure  
  # good or bad, this needs to be done  
end  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment