Created
May 18, 2013 00:26
-
-
Save jimbaker/5602756 to your computer and use it in GitHub Desktop.
Experiment on chained exceptions in Twisted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet.defer import Deferred | |
# presumably should do some sort of chaining like so | |
# http://stackoverflow.com/questions/1350671/inner-exception-with-traceback-in-python | |
# by using methods from twisted.python.failure.Failure | |
# | |
# there may also be better support for this in Twisted already :) | |
def err_handler(failure): | |
failure.trap(OSError) | |
print "Error", failure | |
def err_handler2(failure): | |
print "Error #2", failure | |
d = Deferred() | |
d.errback(Exception(failure)) | |
return d | |
def err_handler3(failure): | |
print "Error #3", failure | |
def stuck(value): | |
print "Should not be here", value | |
d = Deferred() | |
d.addCallbacks(stuck, err_handler) | |
d.addErrback(err_handler2) | |
d.addErrback(err_handler3) | |
print d.errback(KeyError("wtf")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment