Bases: exceptions.Exception
CustomException is an extension of builtin Exception. Goal is to provide an unique structure for all kind of exceptions to allow high-level exception handling.
Typicall use is :
# CustomExceptionNumberFour isn't intercepted here but for example in GUI classes else :
print 'done'
If CustomException takes one argument, you can reach it using "%(value)s". If it takes more than one, you must reimplement _kargs method.
Example :
class ErrNotMatchingPuzzlePiece(CustomException):
title = u'Error: puzzle pieces do not match'
message = u'%(compass_1)s part of piece %(piece_1)%s do not match %(compass_2)s part of piece %(piece_2)%s'
desc = "This error is raised because ..."
def _kargs(self):
return dict(
compass_1=unicode(self._args[0].num),
piece_1=self._args[1],
compass_2=unicode(self._args[2].num),
piece_2=self._args[3],
)
#two raise this exception:
raise ErrNotMatchingPuzzlePiece(p1, u'North', p2, u'South')
# with p1 and p2 two "Piece" objects containing a "num" attribute.