2006/5/19, Yukihiro Matsumoto <matz / ruby-lang.org>: > Hi, > > In message "Re: Rescue clauses on do/end blocks?" > on Fri, 19 May 2006 01:26:09 +0900, uncutstone wu <uncutstone / sina.com> writes: > > |I think the syntax would be changed as below: > | File.open('somefile') do |f| > | puts f.read > | rescue > | puts "Can't open" > | end > > Which do you expect from above code? > > (a) > File.open('somefile') do |f| > begin > puts f.read > rescue > puts "Can't open" > end > end > > (b) > begin > File.open('somefile') do |f| > puts f.read > end > rescue > puts "Can't open" > end > > It's naturally (a) from my point of view, since I know how blocks work > internally. But as you did, many might expect (b). This ambiguity > may become serious disadvantage. Hm, I beg to differ: the "rescue" is *inside* the block so it can catch only exceptions raised from within the block. I for my part would find it rather strange to expect that you can catch an exception that was thrown because of problems opening the file. So my natural expectation would be (a). Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/