Rescue *[]

Shouldn’t these work the same?

irb(main):012:0> begin; raise; rescue; end
=> nil
irb(main):013:0> begin; raise; rescue *[]; end
RuntimeError:
from (irb):13

Hi,

···

At Fri, 30 Jan 2004 08:37:10 +0900, Joel VanderWerf wrote:

Shouldn’t these work the same?

irb(main):012:0> begin; raise; rescue; end
=> nil
irb(main):013:0> begin; raise; rescue *; end
RuntimeError:
from (irb):13

I think rescue without arguments implies StandardError, not
equal to no exceptions, similarly to when *.


Nobu Nakada

Hi,

Shouldn’t these work the same?

irb(main):012:0> begin; raise; rescue; end
=> nil
irb(main):013:0> begin; raise; rescue *; end
RuntimeError:
from (irb):13

I think rescue without arguments implies StandardError, not

Agree.

equal to no exceptions, similarly to when *.

But I would say that both cases are “rescue without arguments”. If I’m
wrong, then rescue argument processing is different from method argument
processing (there may be good reasons for that, of course):

irb(main):001:0> def rescue_method(args); p args; end
=> nil
irb(main):002:0> rescue_method
[]
=> nil
irb(main):003:0> rescue_method(
)

=> nil

···

nobu.nokada@softhome.net wrote:

At Fri, 30 Jan 2004 08:37:10 +0900, > Joel VanderWerf wrote:

Hi,

···

At Fri, 30 Jan 2004 09:38:50 +0900, Joel VanderWerf wrote:

equal to no exceptions, similarly to when *.

But I would say that both cases are “rescue without arguments”. If I’m
wrong, then rescue argument processing is different from method argument
processing (there may be good reasons for that, of course):

Actually, any arbitrary expression can be placed there instead
of . I feel an empty list means nothing should be rescued.


Nobu Nakada

If the argument to rescue is an empty list, you get an error:

irb(main):006:0> begin; raise; rescue ; end
TypeError: class or module required for rescue clause
from (irb):6

If there are no arguments to rescue, you rescue StandardError:

irb(main):007:0> begin; raise; rescue; end
=> nil

How do you get the behavior your describe (“nothing should be rescued”),
except by using the * trick?

I still don’t see why * should behave differently for rescue than for
methods.

···

nobu.nokada@softhome.net wrote:

Hi,

At Fri, 30 Jan 2004 09:38:50 +0900, > Joel VanderWerf wrote:

equal to no exceptions, similarly to when *.

But I would say that both cases are “rescue without arguments”. If I’m
wrong, then rescue argument processing is different from method argument
processing (there may be good reasons for that, of course):

Actually, any arbitrary expression can be placed there instead
of . I feel an empty list means nothing should be rescued.

Hi,

How do you get the behavior your describe (“nothing should be rescued”),
except by using the * trick?

The * trick is the only way (I think) for “nothing should be
rescued”. But I guess it’s OK, since virtually no one want to handle
zero exception in rescue clause.

I still don’t see why * should behave differently for rescue than for
methods.

  • method without argument is common.

  • rescue without capturing exception is very uncommon.

  • but it is still reasonable to leave * as nothing for
    consistency’s sake.

    					matz.
    
···

In message “Re: rescue *” on 04/01/30, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes:

Hi,

How do you get the behavior your describe (“nothing should be rescued”),
except by using the * trick?

irb(main):001:0> def to_be_rescued; ; end
=> nil
irb(main):002:0> begin; raise; rescue *to_be_rescued; end
RuntimeError:
from (irb):2

Here, if to_be_rescued decided nothing to be rescued, it should
not be ignored automagically, IMHO. The method also can return
StandardError explicitly if needed, of course.

···

At Fri, 30 Jan 2004 10:15:09 +0900, Joel VanderWerf wrote:


Nobu Nakada

Yukihiro Matsumoto wrote:

Hi,

How do you get the behavior your describe (“nothing should be rescued”),
except by using the * trick?

The * trick is the only way (I think) for “nothing should be
rescued”. But I guess it’s OK, since virtually no one want to handle
zero exception in rescue clause.

I still don’t see why * should behave differently for rescue than for
methods.

  • method without argument is common.

  • rescue without capturing exception is very uncommon.

  • but it is still reasonable to leave * as nothing for
    consistency’s sake.

      				matz.
    

Ok, thanks for the explanations. I can easily get the behavior I want:

class FooErr < StandardError; end
class BarErr < StandardError; end

def handle_exceptions(*args)
args = [StandardError] if args.empty?
yield
rescue *args
puts “handled”
end

handle_exceptions(FooErr, BarErr) do
raise BarErr
end

handle_exceptions do
raise
end

output:

handled

handled

···

In message “Re: rescue *” > on 04/01/30, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes: