[Python-Dev] GeneratorExit inheriting from Exception
Georg Brandl
g.brandl at gmx.net
Sat Mar 18 16:31:13 CET 2006
More information about the Python-Dev mailing list
Sat Mar 18 16:31:13 CET 2006
- Previous message: [Python-Dev] GeneratorExit inheriting from Exception
- Next message: [Python-Dev] GeneratorExit inheriting from Exception
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Barry Warsaw wrote: > 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 > tree). > > 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: > > Exception > +- KeyboardInterrupt > +- GeneratorExit > +- SystemExit > +- StopIteration > +- Error > | +- ImportError > | +- (etc.) > | > +- Warning > +- UserWarning > +- (etc.) Cool! That's so far the clearest solution. An additional bonus is that except statements look nicer: except: # still catches all Exceptions, just like except Exception: except Error: # is what you normally should do Cheers, Georg
- Previous message: [Python-Dev] GeneratorExit inheriting from Exception
- Next message: [Python-Dev] GeneratorExit inheriting from Exception
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list