[Python-Dev] Pre-PEP: Exception Reorganization for Python 3.0

Phillip J. Eby pje at telecommunity.com
Tue Aug 2 17:48:03 CEST 2005

At 08:00 PM 8/2/2005 +1000, Nick Coghlan wrote:
>Python 2.4 Compatible Improved Exception Hierarchy v 0.1
>+-- ControlFlowException (new)
>       +-- GeneratorExit (new)
>       +-- StopIteration
>       +-- SystemExit
>       +-- KeyboardInterrupt (dual-inheritance new)
>+-- StandardError
>       +-- KeyboardInterrupt (dual-inheritance new)
>       +-- CriticalError (new)
>           +-- MemoryError
>           +-- SystemError
>       +-- Error (new)

Couldn't we make Error a parent of StandardError, here, and then make the 
CriticalError subclasses dual-inherit StandardError, i.e.:

             MemoryError (also subclass StandardError)
             SystemError (also subclass StandardError)

In this way, we can encourage people to inherit from Error.  Or maybe we 
should just make the primary hierarchy the way we want it to be, and only 
cross-link exceptions to StandardError that were previously under 
StandardError, i.e.:

             ...  (cross-inherit to StandardError as needed)
             ...  (cross-inherit to StandardError as needed)

This wouldn't avoid "except Exception" and bare except being problems, but 
at least you can catch the uncatchables and reraise them.

Hm.  Maybe we should include a Reraisable base for ControlFlowException and 
CriticalError?  Then you could do "except Reraisable: raise" as a nice way 
to do the right thing until Python 3.0.

It seems to me that multiple inheritance is definitely the right idea, 
though.  That way, we can get the hierarchy we really want with only a 
minimum of boilerplate in pre-3.0 to make it actually work.

More information about the Python-Dev mailing list