< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #18083 has been updated by ioquatix (Samuel Williams).
There are lots of ways to achieve this but the reality is there is a lot of code which uses `$!` in the ensure block which is incorrect for the reasons already explained.
Your proposed ideas are fine, except that RuboCop will warn you against `rescue Exception`. I agree with the general sentiment around this.
That being said, there are definitely valid use cases where your ensure block wants to know whether it's exiting via a normal code flow or an exceptional one. To answer your question, `ensure => error`, error would be the equivalent of a local `$!`, so nothing really changes, we are just providing a mechanism to do correctly and safely what people are already doing with `$!`.
----------------------------------------
Feature #18083: Capture error in ensure block.
https://bugs.ruby-lang.org/issues/18083#change-93380
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
As discussed in https://bugs.ruby-lang.org/issues/15567 there are some tricky edge cases.
As a general model, something like the following would be incredibly useful:
``` ruby
begin
...
ensure => error
pp "error occurred" if error
end
```
Currently you can get similar behaviour like this:
``` ruby
begin
...
rescue Exception => error
raise
ensure
pp "error occurred" if error
end
```
The limitation of this approach is it only works if you don't need any other `rescue` clause. Otherwise, it may not work as expected or require extra care. Also, Rubocop will complain about it.
Using `$!` can be buggy if you call some method from `rescue` or `ensure` clause, since it would be set already. It was discussed extensively in https://bugs.ruby-lang.org/issues/15567 if you want more details.
--
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>