shevegen (Robert A. Heiler) wrote:
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).
Yeah, this is a proposal to extend the available keywords in ruby core. So ideally, there would be release notes and documentation that would help guide people to this new feature.
- 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).
This is coming from a need that I personally face often on the utilities I work on, where I need to update state on an object if something unexpected happens. My company's linter gets upset when I use the rescue StandardError pattern, so I was hoping to have a way to be more explicit that I'm not trying to prevent the error from going up the stack, I just want to act upon the exception.
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?
Yeah, there's the nicety of being able to reduce a line, but even more enticing is how explicit this pattern feels, and how it can be less error-prone (by forgetting to reraise, or by accidentally casting too wide of a rescue net).
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. :)