[Python-Dev] Bare except clauses in PEP 348

Barry Warsaw barry at python.org
Wed Aug 24 17:03:52 CEST 2005

On Wed, 2005-08-24 at 10:34, James Y Knight wrote:

> I would rather see "except:" be deprecated eventually, and force the  
> user to say either except Exception, except BaseException, or even  
> better, except ActualExceptionIWantToCatch.

I agree about bare except, but there is a very valid use case for an
except clause that catches every possible exception.  We need to make
sure we don't overlook this use case.  As an example, say I'm building a
transaction-aware system, I'm going to want to write code like this:

txn = new_transaction()
    rtn = do_work()
except AllPossibleExceptions:
    return rtn

I'm fine with not spelling that except statement as "except:" but I
don't want there to be any exceptions that can sneak past that middle
suite, including non-errors like SystemExit or KeyboardInterrupt.

I can't remember ever writing a bare except with a suite that didn't
contain (end in?) a bare raise.  Maybe we can allow bare except, but
constrain things so that the only way out of its suite is via a bare


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20050824/46c9f344/attachment.pgp

More information about the Python-Dev mailing list