ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "jeremyevans0 (Jeremy Evans) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "jeremyevans0 (Jeremy Evans)" <noreply@ruby-lang.org>
Subject: [ruby-core:115756] [Ruby master Feature#18083] Capture error in ensure block.
Date: Fri, 15 Dec 2023 20:20:08 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-105694.20231215202007.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18083.20210818030342.3344@ruby-lang.org

Issue #18083 has been updated by jeremyevans0 (Jeremy Evans).


ioquatix (Samuel Williams) wrote in #note-29:
> In the first instance, the question we need to answer is: "Is there a valid use case for $! (assuming dynamic scope as proposed) that isn't better addressed using existing techniques?".
> 
> If the answer is YES, we should implement it.
> 
> If the answer is NO, we should deprecate and remove `$!`.

This perspective ignores backwards compatibility.  If the answer is NO, we would still need to determine if the benefit of removing `$!` exceeds the cost of the loss of backwards compatibility.

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

* 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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2023-12-15 20:20 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` jeremyevans0 (Jeremy Evans) via ruby-core [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-105694.20231215202007.3344@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).