[Python-Dev] Bare except clauses in PEP 348
James Y Knight
foom at fuhm.net
Wed Aug 24 17:23:52 CEST 2005
On Aug 24, 2005, at 11:10 AM, Guido van Rossum wrote:
> On 8/24/05, Michael Chermside <mcherm at mcherm.com> wrote:
>> Explicit is better than Implicit. I think that in newly written code
>> "except Exception:" is better (more explicit and easier to
>> than "except:" Legacy code that uses "except:" can remain
>> unchanged *IF*
>> the meaning of "except:" is unchanged... but I think we all agree
>> this is unwise because the existing meaning is a tempting trap for
>> unwary. So I don't see any advantage to keeping bare "except:" in the
>> long run. What we do to ease the transition is a different question,
>> but one more easily resolved.
> OK, I'm convinced. Let's drop bare except for Python 3.0, and
> deprecate them until then, without changing the meaning.
> The deprecation message (to be generated by the compiler!) should
> steer people in the direction of specifying one particular exception
> (e.g. KeyError etc.) rather than Exception.
I agree but there's the minor nit of non-Exception exceptions.
I think it must be the case that raising an object which does not
derive from an exception class must be deprecated as well in order
for "except:" to be deprecated. Otherwise, there is nothing you can
change "except:" to in order not to get a deprecation warning and
still have your code be correct in the face of documented features of
More information about the Python-Dev