Class t.p.f.Failure:

Part of twisted.python.failure View Source View In Hierarchy

Known subclasses: twisted.spread.pb.CopiedFailure, twisted.spread.pb.CopyableFailure

A basic abstraction for an error that has occurred.

This is necessary because Python's built-in error mechanisms are inconvenient for asynchronous communication.
Instance VariablesvalueThe exception instance responsible for this failure.
typeThe exception's class.
Method __init__ Initialize me with an explanation of the error.
Method trap Trap this failure if its type is in a predetermined list.
Method check Check if this failure's type is in a predetermined list.
Method raiseException raise the original exception, preserving traceback
Method __repr__ Undocumented
Method __str__ Undocumented
Method __getstate__ Avoid pickling objects in the traceback.
Method cleanFailure Remove references to other objects, replacing them with strings.
Method getErrorMessage Get a string of the exception which caused this Failure.
Method getBriefTraceback Undocumented
Method getTraceback Undocumented
Method printTraceback Emulate Python's standard error reporting mechanism.
Method printBriefTraceback Print a traceback as densely as possible.
Method printDetailedTraceback Print a traceback with detailed locals and globals information.
def __init__(self, exc_value=None, exc_type=None, exc_tb=None): (source)

Initialize me with an explanation of the error.

By default, this will use the current exception (sys.exc_info()). However, if you want to specify a particular kind of failure, you can pass an exception as an argument.
def trap(self, *errorTypes): (source)

Trap this failure if its type is in a predetermined list.

This allows you to trap a Failure in an error callback. It will be automatically re-raised if it is not a type that you expect.

The reason for having this particular API is because it's very useful in Deferred errback chains:

| def _ebFoo(self, failure): | r = failure.trap(Spam, Eggs) | print 'The Failure is due to either Spam or Eggs!' | if r == Spam: | print 'Spam did it!' | elif r == Eggs: | print 'Eggs did it!'

If the failure is not a Spam or an Eggs, then the Failure will be 'passed on' to the next errback.
ParameterserrorTypes(type: Exception )
def check(self, *errorTypes): (source)
Check if this failure's type is in a predetermined list.
ParameterserrorTypes(type: list of Exception classes or fully-qualified class names. )
Returnsthe matching Exception type, or None if no match.
def raiseException(self): (source)
raise the original exception, preserving traceback information if available.
def __repr__(self): (source)
Undocumented
def __str__(self): (source)
Undocumented
def __getstate__(self): (source)
Avoid pickling objects in the traceback.
def cleanFailure(self): (source)
Remove references to other objects, replacing them with strings.
def getErrorMessage(self): (source)
Get a string of the exception which caused this Failure.
def getBriefTraceback(self): (source)
Undocumented
def getTraceback(self, elideFrameworkCode=0, detail='default'): (source)
Undocumented
def printTraceback(self, file=None, elideFrameworkCode=0, detail='default'): (source)
Emulate Python's standard error reporting mechanism.
def printBriefTraceback(self, file=None, elideFrameworkCode=0): (source)
Print a traceback as densely as possible.
def printDetailedTraceback(self, file=None, elideFrameworkCode=0): (source)
Print a traceback with detailed locals and globals information.
API Documentation for twisted, generated by pydoctor.