[Python-Dev] Tidier Exceptions

Brett C. bac at OCF.Berkeley.EDU
Fri May 13 22:40:10 CEST 2005


Guido van Rossum wrote:
> [Ka-Ping Yee]
> 
>>Maybe bare 'except' should be spelled 'except *'.
> 
> 
> -1.
> 
> 
>>I don't think it can be removed altogether because sometimes you just
>>need to be able to do magic, but it can be made a little more explicit.
> 
> 
> Assuming a single root of the exception tree, you can spell it
> explicitly as "except Exception" or perhaps (if that's not the root)
> "except Raisable" (cf. Java's Throwable).
> 

There are two possibilities for this.  Either we make all 'except' branches
explicit, or we make bare 'except' branches okay, but not catch the base
exception but the non-critical base exception.

The thinking is that BaseException be the bottom exception, with Exception
being inherited from for non-showstopping exceptions and CriticalException
being for exceptions that you really should not catch unless you mean it
(KeyboardInterrupt, SystemError, MemoryError, etc.).  That would make the bare
'except' much more reasonable.

But personally I still prefer requiring explicit 'except' branches and just
making sure the non-critical base exception is the easier one to type to make
sure people use it by default.

-Brett


More information about the Python-Dev mailing list