Issue #7882 has been updated by phluid61 (Matthew Kerwin).


mame (Yusuke Endoh) wrote:
> I have suggested the same proposal (in Japanese [ruby-dev:31393]).
> Matz said in [ruby-dev:31423] that it is not clear (to him) ...

Definitely the latter.  The rescue statement in the block should only rescue errors that occur inside the block.  This is more apparent if you consider that:

  loop do
  rescue
  finally
  end

is equivalent to:

  x = proc do
  rescue
  finally
  end
  while true
    x.call
  end

Similarly replacing 'while' with a method, such as #each; the 'rescue' in the block should not expect to catch exceptions in the implementation of 'each', only the exceptions raised in the body of the block.
----------------------------------------
Feature #7882: Allow rescue/else/ensure in do..end
https://bugs.ruby-lang.org/issues/7882#change-40195

Author: charliesome (Charlie Somerville)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: current: 2.1.0


=begin
The keywords (({rescue})), (({else})) and (({ensure})) can be used when defining methods like so:

  def foo
    #
  rescue
    #
  else
    #
  ensure
    #
  end

However when using a block delimited by do..end, you must use (({begin}))..(({end})) as well:

  foo do
    begin
      # ...
    rescue
      # ...
      # ...
    end
  end

It would be nice to be able to drop the extra (({begin}))..(({end})) and use (({rescue})), etc. clauses directly:

  foo do
    # ...
  rescue
    # ...
    # ...
  end

I cannot think of any ambiguities this syntax would cause, but please correct me if I am wrong.
=end


-- 
http://bugs.ruby-lang.org/