[Baypiggies] Stylin' in Python..
jeff at drinktomi.com
Sat Jan 5 16:04:35 CET 2008
> The sample code (from Learning Python) is included below my
> signature. My question is: Do I need to inherit a most-generic
> exception class? Or, is a non-exception class sufficient?
Currently no, you don't *need* to inherit from a most-generic
exception class, but in Python 3000 all exceptions must descend
from BaseException, so now is the time to start getting used to
the new world order.
In the current world, if my exceptions designate error conditions
of any kind then they descend from (at least) Exception. The
broad categories defined by Python are:
BaseException - An exception, but not necessarily an error
Exception(BaseException) - An error
StandardError(Exception) - Generic error
ArithmeticError(Exception) - Bad math
LookupError(Exception) - Indexing error
EnvironmentError(Exception) - Something outside python
Only when the exception is used for "normal" flow control do I see
a reason for inheriting directly from BaseException. This is the
pretty much the way Python does it too. GeneratorExit, StopIteration,
SystemExit, and KeyboardInterrupt are all about flow control, and not
errors per se, so they are BaseExceptions, but not Exceptions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies