Object as second parameter to raise

Hi

I’ve just realised that I’ve been inadvertently passing objects other
than strings to raise. As in this example:

class Foo
def bar
:bar
end
end

begin
raise RuntimeError, Foo.new
rescue => e
puts e.message.bar # prints bar in 1.8.6 MRI and 1.9.1 YARV
end

While this works, and is quite useful, I suspect it’s an artefact and
isn’t supported in other Ruby VMs?

Thanks

Paul

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs