ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:104960] [Ruby master Feature#18083] Capture error in ensure block.
@ 2021-08-18  3:03 ioquatix (Samuel Williams)
  2021-08-18  3:09 ` [ruby-core:104962] " ioquatix (Samuel Williams)
                   ` (30 more replies)
  0 siblings, 31 replies; 32+ messages in thread
From: ioquatix (Samuel Williams) @ 2021-08-18  3:03 UTC (permalink / raw)
  To: ruby-core

Issue #18083 has been reported by ioquatix (Samuel Williams).

----------------------------------------
Feature #18083: Capture error in ensure block.
https://bugs.ruby-lang.org/issues/18083

* 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/

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2023-12-15 21:41 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18  3:03 [ruby-core:104960] [Ruby master Feature#18083] Capture error in ensure block ioquatix (Samuel Williams)
2021-08-18  3:09 ` [ruby-core:104962] " ioquatix (Samuel Williams)
2021-08-18 17:04 ` [ruby-core:104971] " Eregon (Benoit Daloze)
2021-08-18 17:09 ` [ruby-core:104972] " Eregon (Benoit Daloze)
2021-08-18 23:04 ` [ruby-core:104980] " ioquatix (Samuel Williams)
2021-08-19  0:45 ` [ruby-core:104981] " duerst
2021-08-19  0:51 ` [ruby-core:104982] " ioquatix (Samuel Williams)
2021-08-19  1:00 ` [ruby-core:104984] " ioquatix (Samuel Williams)
2021-08-19  8:04 ` [ruby-core:105001] " ioquatix (Samuel Williams)
2021-08-19  8:19 ` [ruby-core:105002] " matz (Yukihiro Matsumoto)
2021-08-19  9:57 ` [ruby-core:105005] " ioquatix (Samuel Williams)
2021-08-19 16:42 ` [ruby-core:105013] " Eregon (Benoit Daloze)
2021-08-20  1:09 ` [ruby-core:105019] " ioquatix (Samuel Williams)
2021-08-20 22:00 ` [ruby-core:105033] " Eregon (Benoit Daloze)
2021-08-20 22:03 ` [ruby-core:105034] " ioquatix (Samuel Williams)
2021-08-20 22:09 ` [ruby-core:105035] " Eregon (Benoit Daloze)
2021-08-21  0:52 ` [ruby-core:105036] " ioquatix (Samuel Williams)
2021-10-19  4:46 ` [ruby-core:105667] " ko1 (Koichi Sasada)
2021-10-19 17:51 ` [ruby-core:105682] " Eregon (Benoit Daloze)
2021-10-21  6:13 ` [ruby-core:105715] " ko1 (Koichi Sasada)
2021-10-21  6:28 ` [ruby-core:105716] " matz (Yukihiro Matsumoto)
2021-10-21 10:24 ` [ruby-core:105727] " Eregon (Benoit Daloze)
2021-10-21 11:15 ` [ruby-core:105728] " ioquatix (Samuel Williams)
2021-10-21 11:17 ` [ruby-core:105729] " ioquatix (Samuel Williams)
2021-10-21 13:00 ` [ruby-core:105733] " nobu (Nobuyoshi Nakada)
2023-12-14 19:40 ` [ruby-core:115747] " ioquatix (Samuel Williams) via ruby-core
2023-12-14 20:08 ` [ruby-core:115748] " kddnewton (Kevin Newton) via ruby-core
2023-12-15 14:46 ` [ruby-core:115752] " Dan0042 (Daniel DeLorme) via ruby-core
2023-12-15 20:15 ` [ruby-core:115755] " ioquatix (Samuel Williams) via ruby-core
2023-12-15 20:20 ` [ruby-core:115756] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-12-15 20:30 ` [ruby-core:115757] " ioquatix (Samuel Williams) via ruby-core
2023-12-15 21:41 ` [ruby-core:115759] " Dan0042 (Daniel DeLorme) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).