twisted :: python :: failure :: Failure :: Class Failure
[hide private]
[frames] | no frames]

Class Failure

Known Subclasses:

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 Methods [hide private]
 
__init__(self, exc_value=None, exc_type=None, exc_tb=None)
Initialize me with an explanation of the error.
 
trap(self, *errorTypes)
Trap this failure if its type is in a predetermined list.
 
check(self, *errorTypes)
Check if this failure's type is in a predetermined list.
 
raiseException(self)
raise the original exception, preserving traceback information if available.
 
throwExceptionIntoGenerator(self, g)
Throw the original exception into the given generator, preserving traceback information if available.
 
__repr__(self)
 
__str__(self)
 
__getstate__(self)
Avoid pickling objects in the traceback.
 
cleanFailure(self)
Remove references to other objects, replacing them with strings.
 
getTracebackObject(self)
Get an object that represents this Failure's stack that can be passed to traceback.extract_tb.
 
getErrorMessage(self)
Get a string of the exception which caused this Failure.
 
getBriefTraceback(self)
 
getTraceback(self, elideFrameworkCode=0, detail='default')
 
printTraceback(self, file=None, elideFrameworkCode=0, detail='default')
Emulate Python's standard error reporting mechanism.
 
printBriefTraceback(self, file=None, elideFrameworkCode=0)
Print a traceback as densely as possible.
 
printDetailedTraceback(self, file=None, elideFrameworkCode=0)
Print a traceback with detailed locals and globals information.
 
__providedBy__(...)
Object Specification Descriptor
Class Methods [hide private]
 
_findFailure(cls)
Find the failure that represents the exception currently in context.
Class Variables [hide private]
  pickled = 0
  stack = None
  _yieldOpcode = 'V'
  __implemented__ = <implementedBy twisted.python.failure.Failure>
  __provides__ = <zope.interface.declarations.ClassProvides obje...
Instance Variables [hide private]
  type
The exception's class.
  value
The exception instance responsible for this failure.
Method Details [hide private]

__init__(self, exc_value=None, exc_type=None, exc_tb=None)
(Constructor)

 

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.

If no exc_value is passed, then an "original" Failure will be searched for. If the current exception handler that this Failure is being constructed in is handling an exception raised by raiseException, then this Failure will act like the original Failure.

trap(self, *errorTypes)

 

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.

Parameters:
  • errorTypes (Exception)

check(self, *errorTypes)

 

Check if this failure's type is in a predetermined list.

Parameters:
  • errorTypes (list of Exception classes or fully-qualified class names.)
Returns:
the matching Exception type, or None if no match.

throwExceptionIntoGenerator(self, g)

 

Throw the original exception into the given generator, preserving traceback information if available.

Returns:
The next value yielded from the generator.
Raises:
  • StopIteration - If there are no more values in the generator.

getTracebackObject(self)

 

Get an object that represents this Failure's stack that can be passed to traceback.extract_tb.

If the original traceback object is still present, return that. If this traceback object has been lost but we still have the information, return a fake traceback object (see _Traceback). If there is no traceback information at all, return None.


Class Variable Details [hide private]

__provides__

Value:
<zope.interface.declarations.ClassProvides object at 0x87131cc>