Package twisted :: Package python :: Module failure :: Class Failure

[frames | no frames]

## Class Failure

Known Subclasses:
  `CopiedFailure`, `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.

Method Summary
| ``__init__`(self, exc_value, exc_type, exc_tb)` Initialize me with an explanation of the error.
| ``__getstate__`(self)` Avoid pickling objects in the traceback.
| `__repr__(self)`
| `__str__(self)`
| `check(self, *errorTypes)`
| ``cleanFailure`(self)` Remove references to other objects, replacing them with strings.
| `getBriefTraceback(self)`
| ``getErrorMessage`(self)` Get a string of the exception which caused this Failure.
| `getTraceback(self)`
| ``printBriefTraceback`(self, file)` Print a traceback as densely as possible.
| ``printDetailedTraceback`(self, file)` Print a traceback with detailed locals and globals information.
| ``printTraceback`(self, file)` Emulate Python's standard error reporting mechanism.
| ``trap`(self, *errorTypes)` Trap this failure if its type is in a predetermined list.

Instance Variable Summary
| `type`: The exception's class.
| `value`: The exception instance responsible for this failure.

Class Variable Summary
`int` | `pickled` = 0
`NoneType` | `stack` = None

Method Details

### __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.

### __getstate__(self)

Avoid pickling objects in the traceback.

### cleanFailure(self)

Remove references to other objects, replacing them with strings.

### getErrorMessage(self)

Get a string of the exception which caused this Failure.

### printBriefTraceback(self, file=None)

Print a traceback as densely as possible.

### printDetailedTraceback(self, file=None)

Print a traceback with detailed locals and globals information.

### printTraceback(self, file=None)

Emulate Python's standard error reporting mechanism.

### 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`
    (type=`Exception`)

Instance Variable Details

### type

The exception's class.

### value

The exception instance responsible for this failure.

Class Variable Details

### pickled

  Type:
    `int`
  Value:

        0

### stack

  Type:
    `NoneType`
  Value:

        None

Generated by Epydoc 2.0 on Sat May 15 20:08:10 2004 | http://epydoc.sf.net