Issue #12623 has been updated by Martin Drst.


Nobuyoshi Nakada wrote:

> An objection is that `rescue` in `{}` block feels weird.

I feel the same way. I think it feels weird because in Ruby, program structures starting with a keyword (`if`/`while`/`do`/`def`/...) can contain keywords (`else`, `rescue`,...) and end with keywords (`end`), but symbols (`{}`, `[]`,...) and keywords are not mixed.

This, combined with the fact that `{}` is mostly used single-line, may suggest that adding `rescue` to `do` blocks might work, but not for `{}` blocks.

----------------------------------------
Feature #12623: rescue in blocks without begin/end
https://bugs.ruby-lang.org/issues/12623#change-59810

* Author: Dmitriy Non
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hi there!

There's pretty nice feature that we can use "short rescue" in method definitions: 

~~~ruby
def my_method
  raise '1234'
rescue
   puts 'rescued'
end
~~~

What about using this in blocks?

~~~ruby
loop do
  n = enumerator.next
  # do something
rescue StopIteration
end
~~~

P.S. actually I am not sure if this FR was not created earlier but I couldn't google it.
P.P.S sorry for my english



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>