Ruby Keyword: rescue - rking/pry-docmore GitHub Wiki

Catch exceptions.

Usage:

begin
  1/0
rescue => e
  puts "No division by zero ever bothered me."
end

Or

def foo
  1/0
rescue
  puts "Yep, works on 'def's, too."
end

This is the basic exception heirarchy:

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

More in Avdi Grimm's book, Exceptional Ruby: http://pragprog.com/book/ager/exceptional-ruby

TODO:

Explain the args syntax

Talk about Standard

See: ensure, else, retry

⚠️ **GitHub.com Fallback** ⚠️