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

[show private | hide private]
[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)`
| ``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`
`None` | `stack`

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.

### 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:
    `None`
  Value:

        None

Generated by Epydoc 1.1 on Sat Feb 15 21:18:04 2003 | http://epydoc.sf.net