(Following up to myself to summarise)

On 2010-02-13, Jeremy Henty <onepoint / starurchin.org> wrote:

> I wondered whether  the clause rescue would accept  any modules, not
> just  exception classes.   Well,  at  least in  MRI  1.8.7, it  does
> (example appended).  But will this work in all Ruby implementations?

As  reported  elsewhere  in  the   thread,  this  does  seem  to  work
everywhere.

MRI  1.8.7  raises  "class   or  module  required  for  rescue  clause
(TypeError)" if  the handler  is not a  module.  It tests  whether the
exception matches  the handler with <handler>::=== (I  checked this by
redefining self.#=== inside a module).

"Programming Ruby" (2nd ed.) explicitly  says that the match test uses
#=== .  Its language implicitly presumes  (at least as I read it) that
the handlers should be Exception classes, not arbitrary modules.

The  Draft Ruby  Specification 20091201  disagrees with  everyone!  It
says that  a TypeError is  raised if the  handler is not  an Exception
class.  Furthermore it says that the  exception is handled if it is an
instance of the handler, rather  than if it satisfies <handler>::=== .
This  rather  goes  against  the specification's  stated  intent  that
existing implementations should conform without modification.

Regards,

Jeremy Henty