Robert Klemme wrote:
>> I have low expectations with regard to the "else" clause but the book 
>> clearly states that it is executed if there was no exception - that 
>> includes the case where the block is left via a "return".  Behavior and 
>> description simply are not in sync, that's my point.

Dave Thomas replied:
> Interesting: I'd honestly never have thought of that interpretation.
[...]
> Do you feel I should also document the other places when a return could be 
> issued? For example, in the description of a while loop, I say "executes body 
> zero or more times as long as boolean-expression is true."  Should I add "or 
> a return is executed or an exception is thrown" to this and similar 
> descriptions?
>
> I kind of feel that this would clutter the descriptions, and that most 
> readers would make the assumption that return and exceptions would break the 
> flow.  Is that an incorrect assumption?

I think detailing every condition under which else would not get called is 
overdoing it a bit.

Instead of listing the conditions under which the else might not be 
reached; how about instead of writing "The body of an else clause is 
executed only if no exceptions are raised by the main body of code." You'd 
write "The body of an else clause is executed only if the end of the main 
body of code is reached without causing any exceptions". This to me would 
sound more clear - a return statement in the main block would prevent the 
end of the main body of code to be reached.


So, the difference is just that I can use the else block to insert code 
that will run before the ensure (in your book example before the ensured 
file.close) but outside of the rescue blocks (i.e. code in the else block 
CAN throw an exception which will not be handled in the current 
begin/rescue block...   (Whether this is useful or not, is another 
issue)...


         def testme()
           begin
             begin
               puts "foo"
               #return(1);
 	      puts "raising error"
               puts "bar"
             rescue
               puts "inner rescue block"
             else
               raise ArgumentError.new("blah");
             ensure
               puts "ensured"
             end

           rescue
             puts "outer rescue block"
           end
         end

         testme();

will print

 	foo
 	bar
 	raising error
 	ensured
 	outer rescue block


If I were to uncomment the return(1), it would print

 	foo
 	ensured



Benedikt

   ALLIANCE, n.  In international politics, the union of two thieves who
     have their hands so deeply inserted in each other's pockets that
     they cannot separately plunder a third.
 			(Ambrose Bierce, The Devil's Dictionary)