Question

I have a piece of code:

from twisted.web.client import getPage
from twisted.internet import reactor

class TestError(Exception):
    def __init__(self, message):
        self.message = message
    def __repr__(self):
        return 'TestError'

def gotPage(response):
    print response
    reactor.stop()

def gotErr(failure):
    raise TestError('This is error')

def newEb(failure):
    try:
        failure.raiseException()
    except TestError as te:
        print te.message
    reactor.stop()

if __name__ == '__main__':
    deferred = getPage('http://somebadpage.net', method='GET')
    deferred.addCallback(gotPage)
    deferred.addErrback(gotErr)
    deferred.addErrback(newEb)
    reactor.run()

Is the way presented in newEb the only way to extract the error parameters from failure? When I use failure.trap or failure.check I cannot receive error instance.

Was it helpful?

Solution

If by error parameters you mean the exception instances, then Failure.value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top