On Tue, 14 Nov 2000, ts wrote:

>  write it like this
   [snip my version]
>    def two
>       fh = File.open("roster")
>       begin
> 	 begin
> 	    line = fh.readline
> 	 rescue
> 	    puts $! + " while looking for END"
> 	    exit
> 	 end
>       end until line.is_end?
>       fh.close
>       puts "two: reached END"
>    end

Thanks -- that certainly solves the practical problem.  I am still
intrigued, though, by what is at the root of it.  I've abstracted it
to the following test (not that I would ever do it like this again
except for learning purposes :-)

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

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

Output:

Line from first block.


It seems that if there is a rescue clause, then the until condition
gets tested once *before* the body of the block is executed, so the
block never gets executed at all if the condition is initially true.

This means, I now realize, that one of my original cases that "worked"
(...until line =~ /END/) only worked by coincidence -- because line
was empty initially.

Is it that the until condition is considered part of what rescue is
supposed to rescue us from?  But still -- say the evalution of until
did raise an exception.  Why not execute the block once first, anyway,
and then handle that exception where it occurs?

Besides, it doesn't look like that's what's happening:

   begin
     puts "line"
   rescue NameError
     puts "Hoping to catch exception from until condition...."
   end until 123.no_such_method

Output:

rescue2.rb:7: undefined method `no_such_method' for 123:Fixnum (NameError)

I can now see what order things are happening, but I still don't know
why....

David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav