From: shevegen@... Date: 2019-06-18T22:23:27+00:00 Subject: [ruby-core:93230] [Ruby trunk Feature#15936] on_error in lieu of rescue, raise Issue #15936 has been updated by shevegen (Robert A. Heiler). Hmmm. I have not made up my mind so I can not even say whether this may be interesting or not. But I think just a few general thoughts: - People may expect begin/rescue/end, more than any alternatives. They may wonder what on_error is or how it would be used (or any other name). - Is it very common to use ensure/rescue/re-raise? I have no statistical data but in my own code, but also in code by other people, it seems as if simple begin rescue clauses are highly prevalent. This should not be assumed as a con opinion, I am just pointing this out in context as to whether on_error would be worth to be added (and I honestly do not know). As for potentially pro-points, if I understood one part of your issue correctly then you also suggest being able to handle a specific error-case with this line exactly. Or at the least this is how I understand the code example, where in the second you can omit one line right? These are just some semi-random comments from me - as I wrote above, I really do not even have the slightest idea yet whether I may like, dislike or even just be neutral on it. :) ---------------------------------------- Feature #15936: on_error in lieu of rescue, raise https://bugs.ruby-lang.org/issues/15936#change-78680 * 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>