https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-02-19T22:48:17ZRuby Issue Tracking SystemRuby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=366142013-02-19T22:48:17Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I remember I've seen the same proposal.</p>
<p>What do you think about {} block?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">foo</span> <span class="p">{</span>
<span class="o">...</span>
<span class="k">rescue</span>
<span class="o">...</span>
<span class="p">}</span>
</code></pre>
<p>seems odd to me a little.</p>
<p>Or improve <code>do</code>...<code>end</code> only?</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=366152013-02-19T22:54:45Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>I don't find it that odd, Nobu, although I think most developers would tend to use do-end anyway as we usually do in Ruby when the block span multiple lines.</p>
<p>I like the idea very much actually.</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=366202013-02-19T23:51:30Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>I have suggested the same proposal (in Japanese <a href="https://blade.ruby-lang.org/ruby-dev/31393">[ruby-dev:31393]</a>).<br>
Matz said in <a href="https://blade.ruby-lang.org/ruby-dev/31423">[ruby-dev:31423]</a> that it is not clear (to him) whether:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="kp">loop</span> <span class="k">do</span>
<span class="p">:</span>
<span class="k">rescue</span>
<span class="p">:</span>
<span class="k">ensure</span>
<span class="p">:</span>
<span class="k">end</span>
</code></pre>
<p>should behave like:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">begin</span>
<span class="kp">loop</span> <span class="k">do</span>
<span class="p">:</span>
<span class="k">end</span>
<span class="k">rescue</span>
<span class="p">:</span>
<span class="k">ensure</span>
<span class="p">:</span>
<span class="k">end</span>
</code></pre>
<p>or:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="kp">loop</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="p">:</span>
<span class="k">rescue</span>
<span class="p">:</span>
<span class="k">ensure</span>
<span class="p">:</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=366212013-02-20T00:07:04Zalexeymuranov (Alexey Muranov)
<ul></ul><p>I've heard of a convention to use <code>{ ... }</code> for blocks evaluated for a result and <code>do ... end</code> for blocks evaluated for side effects: <a href="http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc" class="external">http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc</a><br>
From this point of view, there probably shouldn't be any differences in the syntax inside the two forms of blocks.</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=366222013-02-20T00:38:15Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Yusuke, I believe it should be the latter. If you want to rescue from the yielding method you have the option of doing it like this in most cases:</p>
<p>with_transaction do<br>
...<br>
rescue<br>
...<br>
end rescue puts 'with_transaction raised outside the yield block'</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=401952013-06-29T08:03:12Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>I have suggested the same proposal (in Japanese <a href="https://blade.ruby-lang.org/ruby-dev/31393">[ruby-dev:31393]</a>).<br>
Matz said in <a href="https://blade.ruby-lang.org/ruby-dev/31423">[ruby-dev:31423]</a> that it is not clear (to him) ...</p>
</blockquote>
<p>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:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="kp">loop</span> <span class="k">do</span>
<span class="k">rescue</span>
<span class="n">finally</span>
<span class="k">end</span>
</code></pre>
<p>is equivalent to:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">x</span> <span class="o">=</span> <span class="nb">proc</span> <span class="k">do</span>
<span class="k">rescue</span>
<span class="n">finally</span>
<span class="k">end</span>
<span class="k">while</span> <span class="kp">true</span>
<span class="n">x</span><span class="p">.</span><span class="nf">call</span>
<span class="k">end</span>
</code></pre>
<p>Similarly replacing '<code>while</code>' with a method, such as <code>#each</code>; the '<code>rescue</code>' in the block should not expect to catch exceptions in the implementation of '<code>each</code>', only the exceptions raised in the body of the block.</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=447592014-01-30T06:16:46Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>2.1.0</i> to <i>2.2.0</i></li></ul> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=598652016-08-02T01:52:37Zshyouhei (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/11337">Feature #11337</a>: Allow rescue without begin inside blocks</i> added</li></ul> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=598672016-08-02T01:52:54Zshyouhei (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/12623">Feature #12623</a>: rescue in blocks without begin/end</i> added</li></ul> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=600142016-08-09T09:06:41Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/60014/diff?detail_id=42140">diff</a>)</li></ul> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=613692016-11-07T02:28:46Zshyouhei (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 #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=628432017-02-03T16:47:44ZNondv (Dmitry Non)
<ul></ul><p>So... Is there any movement?</p> Ruby master - Feature #7882: Allow rescue/else/ensure in do..endhttps://bugs.ruby-lang.org/issues/7882?journal_id=628532017-02-04T01:33:17Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul>