Abstract Base Classes
Ben Finney
bignose+hates-spam at benfinney.id.au
Thu Nov 10 23:55:13 EST 2005
Mike Meyer <mwm at mired.org> wrote:
> class FooException(Exception):
> def __init__(self):
> if self.__class__ == FooException:
> raise NotImplementedError,
> "FooException is an abstract class for exceptions"
Shall try this when I get the chance. Thanks.
> Personally, I find this unpythonic. FooException doesn't contribute
> anything, and has no real reason for existing.
The purpose is to be able to specify an 'except FooException:' in some
user of that module; this allows exceptions from that particular
module to be handled differently, if necessary. (And so on for a
hierarchy of modules in a package, if that's warranted.)
--
\ "A cynic is a man who knows the price of everything and the |
`\ value of nothing." -- Oscar Wilde |
_o__) |
Ben Finney
More information about the Python-list
mailing list