Issue #10042 has been updated by Quintus (Marvin Glker).


Please add as related: https://bugs.ruby-lang.org/issues/6739

That's a proposal to eliminate the problem described here (antipattern usage because it swallows exceptions) by extending the one-line rescue statement with a possibility to catch exception classes. There wasn't a solution to a proper syntax yet, but I don't think it's required to go through all of that again if we have it in #6739.

Marvin

----------------------------------------
Feature #10042: Deprecate postfix rescue syntax for removal in 3.0
https://bugs.ruby-lang.org/issues/10042#change-70237

* Author: headius (Charles Nutter)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: Next Major
----------------------------------------
The postfix rescue notation is convenient...but almost always is a really bad antipattern.

An example of the notation:

    Integer(f) rescue f # returns f if it is not parseable as an Integer

It silently ignores all StandardError raised by a piece of code...which often covers *many* more exceptions than the user *wants* to be ignoring.

It also hides the cost of constructing and throwing away all those ignored exceptions.

I believe Matz has even said in the past that he regrets adding the feature.

In any case, I propose that "rescue nil" should be deprecated with a warning (either always on or only when verbose) and we should plan to remove it in 3.0.

Who's with me?!



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