tags:

views:

180

answers:

1

Is there a way for something to raise and exception that does not descend from Exception?

What I'm trying to avoid is something like:

require 'timeout'
begin
  timeout(1) {sleep(50)}
rescue StandardError => e
  puts e.message
end

I know I can catch this with 'rescue Exception' or more drastically, 'rescue Object', but that seems a little odd to me.

+1  A: 

If you try to raise an error that's not of the Exception class, you'll get a <TypeError: exception class/object expected>.

kch