[Python-Dev] GeneratorExit inheriting from Exception

Barry Warsaw barry at python.org
Sat Mar 18 16:26:45 CET 2006

On Sat, 2006-03-18 at 22:53 +1000, Nick Coghlan wrote:
> Should GeneratorExit inherit from Exception or BaseException?

Actually, this prompts me to write about an issue I have with PEP 352.
I actually don't think it's necessary (yes, I know it's already in the

What I would much rather is is for StandardError to be renamed Error,
for Exception to remain the base class of the exception hierarchy, and
for KeyboardInterrupt to be moved to inherit directly from Exception.
GeneratorExit, SystemExit, and StopIteration would continue to inherit
from Exception.

The reasoning is this: anything that can be raised is an Exception.  Not
all Exceptions are Errors.  Anything that signals an error condition is
an Error, and anything that signals a warning condition is a Warning.
Thus the basic hierarchy /ought/ to be:

+- KeyboardInterrupt
+- GeneratorExit
+- SystemExit
+- StopIteration
+- Error
|  +- ImportError
|  +- (etc.)
+- Warning
   +- UserWarning
   +- (etc.)

Use defined errors should inherit from Error, not Exception.  With this,
"except Exception" would be a synonym for bare except, while "except
Error" would be the standard idiom for letting non-error exceptions pass

I don't know whether this is possible for Python 2.5, but I think it
should be what we strive for for Py3K, and I do not think BaseException
is at all necessary.


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

More information about the Python-Dev mailing list