Part of twisted.python.failure.Failure View 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.
Parameters | errorTypes | (type: Exception
) |