[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6363] Re: rescue clause affecting IO loop behavior

From: ts <decoux@...>
Date: 2000-11-14 17:25:05 UTC
List: ruby-talk #6363
>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:


 You don't have the same 'begin'

D>    begin
D>      puts "Line from first block."
D>    end until true

 With this 'begin' ruby don't test the first time. This mean that the block
 is always executed once

D>    begin
D>      puts "Line from second block."
D>    rescue
D>      d = "dummy exception handler"
D>    end until true

 Here for ruby you don't have a block 'begin' but a block 'rescue'. This
 mean that ruby will make the test before trying to enter in the block
 'rescue'

 Perhaps ruby must test if it has a block 'rescue', or a block 'ensure' and
 skip the first test like it do with a block 'begin', I don't know ?

 For your example :

 # here line is nil
 # because you have a block 'begin' ruby don't call the first time
 # 'line.is_end?' and enter directly in the block
     begin
# it read a line ==> now line is a String object
       line = fh.readline
# it try to call the method String#is_end? and find it
     end until line.is_end?


 This is why it work

 The second case

 # here line is nil
 # because you don't have a block 'begin' but a block 'rescue' ruby will
 # make the test *before* trying to enter in the block,
 # this mean that it go directly to the until part
     begin                        
       line = fh.readline         
     rescue
       puts $! + " while looking for END" 
       exit                               
# line is nil, and it will try to call the method Nil#is_end?
# and don't find it, this is why it give the error.
     end until line.is_end?


 This is why your example work when you have a method associated with nil,
 and don't work otherwise



Guy Decoux


In This Thread

Prev Next