< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #15936 has been updated by jeremyevans0 (Jeremy Evans).
kylemacey (Kyle Macey) wrote:
> What would be a thought on using another keyword that doesn't actually _rescue_ an exception, but performs an operation in the event of an error? Similar to `ensure`, but only in the event of an error.
>
> ```
> begin
> some_method
> on_error StandardError
> job.fail!
> end
> ```
Thankfully, Ruby already supports what you want:
```ruby
begin
some_method
ensure
job.fail! if $! # or use case $! if you want to handle specific exception classes differently
end
```
As you can already accomplish this with current Ruby syntax, I do not think adding a keyword for it is warranted.
----------------------------------------
Feature #15936: on_error in lieu of rescue, raise
https://bugs.ruby-lang.org/issues/15936#change-78689
* Author: kylemacey (Kyle Macey)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
A common bad pattern in ruby is to rescue any exception and accidentally clobber the exception.
```
begin
some_method
rescue StandardError
#
end
```
Most linters will complain if you write rescues like the code above. However, this could be useful if we want to perform an operation on _any_ error, as long as we re-raise the exception after doing our work.
```
begin
some_method
rescue StandardError
job.fail!
raise
end
```
Here, though, we run the risk of potentially forgetting to reraise the exception, or having to make exceptions in our linter for an operation that is overall benign.
What would be a thought on using another keyword that doesn't actually _rescue_ an exception, but performs an operation in the event of an error? Similar to `ensure`, but only in the event of an error.
```
begin
some_method
on_error StandardError
job.fail!
end
```
(obviously, someone more creative than me should come up with a better name)
--
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>