Custom exceptions -- inherit from exceptions.Exception?

Paul Miller pwmiller1 at adelphia.net
Wed Nov 12 01:59:08 EST 2003


Is there any particular good reason to inherit from
exceptions.Exception?  I've never seen any code that depends on what
the base class(es) of a raised exception is (are).

My use case is in a game I am writing.  The code for my Game class
contains the following:

class Game (object):

    def start (self):
        try:
            self.players[1]
        except IndexError:
            raise NotEnoughPlayers

where NotEnoughPlayers is really just an empty classic class suitable
for raising.  Is there any benefit to importing exceptions and
inheriting from exceptions.Exception, other than maybe theoretical
purity?

Thanks!




More information about the Python-list mailing list