[Python-ideas] Proposal: Abolition of bare except clauses
Terry Reedy
tjreedy at udel.edu
Sat Apr 11 21:18:25 CEST 2015
On 4/11/2015 7:29 AM, Chris Angelico wrote:
> A bare "except:" clause catches any exception. As of Python 3.0, this
> can be spelled more explicitly as "except BaseException:", and AFAIK
> the only difference between the two is that someone might rebind
> BaseException.
>
> String exceptions were abolished during the 2.x line, without causing
> major upheaval. The deprecation and ultimate abolition of the bare
> except syntax would have less consequence than that, as it would
> merely require a mechanical transformation to "except BaseException:",
> without needing any corresponding changes at raise site.
> Thoughts?
* There are about 20 bare excepts in idlelib and an issue (15313) to
remove them by adding the missing class or tuple. I have looked at a
few and found it is hard to determine what should be added. I may
eventually just add Exception if I cannot be more specific (or general).
* 'except:' is easily caught by a code checker, or reported by grep.
This works both ways: don't need to change the language, but equally
easy to find to change if the language is changed.
* As Steven said, there could be a long deprecation period.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list