From: Daniel Nugent Date: 2006-02-13T06:46:27+09:00 Subject: Re: Rescuing blocks? Sorry, not sure what the issue is (I assume you mean rescue, not raise there). If a rescue appears after a statement, it only applies to thatstatement. If a rescue appears as the first token on a line, itapplies to the enclosing block. I'm pretty sure that's how it worksnow. If you're talking about doing something like... foo.each{|o| raise "Oh noes, it's number 2!" if o == 2; rescueException => e; puts e.to_s} It's still obvious how it works. On 2/12/06, David Vallner wrote:> How would you parse the difference whether the raise applies to the whole> block, or just the previous statement?>> David Vallner>> D�a Nede�a 12 Febru�r 2006 21:43 Daniel Nugent nap�sal:> > Is> >> > foo.each {|o|> > raise "Oh noes, it's number 2!" if o == 2> > rescue Exception => e> > puts e.to_s> > }> >> > really that hideous?> >> > On 2/12/06, David Vallner wrote:> > > D�a Nede�a 12 Febru�r 2006 20:39 Mark Volkmann nap�sal:> > > > On 2/12/06, Lou Vanek wrote:> > > > > 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> > > >> > > > Sure it works, but Daniel wants to reduce the syntax a bit AND exit> > > > the loop if an exception is raised without having to specify that. I> > > > like his suggestion.> > > >> > > > --> > > > R. Mark Volkmann> > > > Partner, Object Computing, Inc.> > >> > > It would cause a little inconsistency with the curly brace form of> > > blocks. Either the rescue clause would have to work only for the do / end> > > form, or we'd be mixing braces and keywords in a single construct, which> > > I couldn't bear to look at.> > >> > > David Vallner> >> > --> > -Dan Nugent>> ---Dan Nugent