Seems like you are using an older version of Ruby. According to the 1.8.7 docs it raises an IndexError
:
Returns a value from the hash for the given key. If the key can’t be found, there are several options: With no other arguments, it will raise an IndexError exception; if default is given, then that will be returned; if the optional code block is specified, then that will be run and its result returned.
Note that KeyError
is a subclass of IndexError
in Ruby 1.9+, so rescuing IndexError
works, too.