Project

General

Profile

Actions

Feature #13212

closed

Syntax proposal: don't require begin-end to rescue exceptions inside do-end blocks

Added by Nowaker (Damian Nowak) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:79523]

Description

Blocks are ubiquitous in Ruby world. There's as many blocks in every Ruby code as methods - if not even more. It would be very nice to treat blocks as first class citizens like methods and reduce the undesirable begin-end boilerplate inside blocks for exception handling. Here's the syntax proposal:

arr.each do |e|
  do_something(e)
rescue MyException => e
  # handle exception
end

Just like in methods:

def method
  do_something
rescue MyException => ex
  # handle exception
end

Currently begin-end block is required for handling exceptions inside blocks:

arr.each do |e|
  begin
    do_something(e)
  rescue MyException => ex
    # handle exception
  end
end

Whether the same syntax would apply for {} block/lambda syntax is debatable. {} are typically one-liners and I barely ever saw a begin-rescue-end inside them.

Thank you
-Damian Nowak


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #12906: do/end blocks work with ensure/rescue/elseClosednobu (Nobuyoshi Nakada)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0