Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > rescue *[]

Reply
Thread Tools

rescue *[]

 
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-29-2004

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




 
Reply With Quote
 
 
 
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      01-30-2004
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


 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-30-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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


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



 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      01-30-2004
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


 
Reply With Quote
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-30-2004
(E-Mail Removed) 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.


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.



 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      01-30-2004
Hi,

In message "Re: rescue *[]"
on 04/01/30, Joel VanderWerf <(E-Mail Removed)> writes:

|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.


 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      01-30-2004
Hi,

At Fri, 30 Jan 2004 10:15:09 +0900,
Joel VanderWerf wrote:
> 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.

--
Nobu Nakada


 
Reply With Quote
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-30-2004
Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: rescue *[]"
> on 04/01/30, Joel VanderWerf <(E-Mail Removed)> writes:
>
> |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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozila rescue from ntuser.dat corruption Adam Smith Firefox 1 10-20-2005 03:31 PM
Mars Rescue Mission Challenge Frank Buss Java 8 11-20-2004 01:12 AM
Creating rescue diskettes for AVG Mike NG Computer Support 3 08-13-2003 11:34 AM
Custom Windows Rescue CD? Lee J. Computer Support 3 08-05-2003 09:34 PM
rescue the value of a variable type application from a file ".vb" clv ASP .Net 0 07-01-2003 11:23 PM



Advertisments