https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-07-24T19:29:30ZRuby Issue Tracking SystemRuby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=597842016-07-24T19:29:30ZNondv (Dmitry Non)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/59784/diff?detail_id=42000">diff</a>)</li></ul> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=597892016-07-25T18:18:51Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>+1, I often want this and never understood why it only worked with methods.</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=597932016-07-26T01:59:02Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/59793/diff?detail_id=42006">diff</a>)</li></ul><p>AFAIK, it has been proposed a few times.</p>
<p>An objection is that <code>rescue</code> in <code>{}</code> block feels weird.</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=597992016-07-26T13:00:57ZNondv (Dmitry Non)
<ul></ul><blockquote>
<p>An objection is that rescue in {} block feels weird.</p>
</blockquote>
<p>Do you mean in one-line or multi-line form?</p>
<p>Multiline:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">list</span><span class="p">.</span><span class="nf">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span>
<span class="c1"># do something</span>
<span class="k">rescue</span>
<span class="c1"># do something</span>
<span class="p">}</span>
</code></pre>
<p>In single-line there's ambiguous case:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># not implemented</span>
<span class="n">list</span><span class="p">.</span><span class="nf">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">action_1</span><span class="p">;</span> <span class="n">action_2</span><span class="p">;</span> <span class="k">rescue</span><span class="p">;</span> <span class="s1">'error!'</span> <span class="p">}</span>
<span class="c1"># this is valid</span>
<span class="n">list</span><span class="p">.</span><span class="nf">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">action_1</span><span class="p">;</span> <span class="n">action_2</span> <span class="k">rescue</span> <span class="s1">'error!'</span> <span class="p">}</span>
</code></pre>
<p>But 2nd line looks bad anyway :(</p>
<p>So, what's problem of "feels weird"?<br>
IMHO there're not many people that will use it like that (my first example in single-line).</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=598072016-07-27T04:23:35Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>Dmitriy Non wrote:</p>
<blockquote>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">list</span><span class="p">.</span><span class="nf">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span>
<span class="c1"># do something</span>
<span class="k">rescue</span>
<span class="c1"># do something</span>
<span class="p">}</span>
</code></pre>
</blockquote>
<p>-1. This is odd. I cannot remember any other language syntax that goes likes this. Java, C++, C# and all other language that use {} as block notations share this syntax to write exception handlings:</p>
<pre><code class="csharp syntaxhl" data-language="csharp"><span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">try</span>
<span class="p">{</span>
<span class="c1">// something</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="n">Exception</span> <span class="n">e</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// something</span>
<span class="p">}</span>
<span class="k">finally</span>
<span class="p">{</span>
<span class="c1">// something</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=598092016-07-27T07:52:10ZNondv (Dmitry Non)
<ul></ul><blockquote>
<p>I cannot remember any other language syntax</p>
</blockquote>
<p>So, case statement in Ruby is different too.</p>
<p>+ it is not necessary to use this.<br>
BTW AFAIK ruby-style-guide banned multiline {}</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=598102016-07-27T08:11:37Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>An objection is that <code>rescue</code> in <code>{}</code> block feels weird.</p>
</blockquote>
<p>I feel the same way. I think it feels weird because in Ruby, program structures starting with a keyword (<code>if</code>/<code>while</code>/<code>do</code>/<code>def</code>/...) can contain keywords (<code>else</code>, <code>rescue</code>,...) and end with keywords (<code>end</code>), but symbols (<code>{}</code>, <code>[]</code>,...) and keywords are not mixed.</p>
<p>This, combined with the fact that <code>{}</code> is mostly used single-line, may suggest that adding <code>rescue</code> to <code>do</code> blocks might work, but not for <code>{}</code> blocks.</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=598662016-08-02T01:52:54Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/7882">Feature #7882</a>: Allow rescue/else/ensure in do..end</i> added</li></ul> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=599202016-08-04T06:50:30Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Closing duplicated issue. Please continue discussing at Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Allow rescue/else/ensure in do..end (Closed)" href="https://bugs.ruby-lang.org/issues/7882">#7882</a>.</p> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=613732016-11-07T02:29:21Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/12906">Feature #12906</a>: do/end blocks work with ensure/rescue/else</i> added</li></ul> Ruby master - Feature #12623: rescue in blocks without begin/endhttps://bugs.ruby-lang.org/issues/12623?journal_id=955552021-12-23T23:41:09Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li></ul>