[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
>========================================================
>
>Exception
>+-- 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.:
Error
CriticalError
MemoryError (also subclass StandardError)
SystemError (also subclass StandardError)
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.:
Raisable
ControlFlowException
... (cross-inherit to StandardError as needed)
CriticalError
... (cross-inherit to StandardError as needed)
Exception
...
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