vanekl
2/12/2006 7:10:00 PM
this works,
foo = [1, 2, 3]
foo.each do |o|
begin
raise "Oh noes, it's number 2!" if o == 2
rescue Exception => e
puts e.to_s
end
end
Daniel Nugent wrote:
> Whoops, shoulda thought of that, a-doy.
>
> Okay, it's pretty simple, here's what I'd like to do (you can
> extrapolate the rest of the syntax from the simple example):
>
> foo = [1, 2, 3]
>
> foo.each do |o|
> raise "Oh noes, it's number 2!" if o == 2
> rescue Exception => e
> puts e.to_s
> end
>
> And so on and so forth. It seems pretty natural to me.... I don't
> think it breaks anything (least not off the top of my head)...
>
> On 2/12/06, David Vallner <david@vallner.net> wrote:
>
>>Dna Nedela 12 Február 2006 19:26 Daniel Nugent napísal:
>>
>>>Hey guys,
>>>
>>>I was working on a DSL for some asynchronous programming stuff and I
>>>realized it'd be really nice if a block could rescue an exception.
>>>
>>>So I went into IRB to see if it works and got a parse error. I
>>>suppose you need a begin... end block or a proper method to have a
>>>rescue block right now.
>>>
>>>I was wondering if there's any reason why this is so? It'd seem
>>>pretty natural to me that a block could have rescue/else/ensure
>>>conditions since a method body can have them.
>>>
>>>Has this been discussed elsewhere?
>>>
>>>Thanks,
>>>
>>>--
>>>-Dan Nugent
>>
>>I'm afraid I don't quite catch your drift. What do you mean by a block not
>>rescuing an exception? Some example code wouldn't hurt.
>>
>>David Vallner
>>
>>
>
>
>
> --
> -Dan Nugent