Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal Errors and Deferreds in Twisted, stop a deferred
    text
    copied!<p>I have a problem, with normal try except blocks in python you can just return if there is a fatal error, ex...</p> <pre><code>try: logon() except 404_Error: retry_logon(try = 2) except AuthenticationProblem: error_label.SetText( "You password or username was wrong. Make sure that CAPS LOCK key is not on." ) return#nothing more we can do here else: #display user information or whatever </code></pre> <p>So how do this with deferreds, if I just return it goes onto execute the callbacks thinking the error is handled but how do I inform the user something went wrong and destroy the down river chain.</p> <p>==== Update ===</p> <p>mg thanks for the help but it didn't work, even with a fatal error the defer still returns to the callbacks afterwords</p> <pre><code>from twisted.internet import reactor from twisted.internet.defer import Deferred as D class NonFatalError(Exception): 'non fatal error' class FatalError(Exception): 'fatal error' def c(s): print "Callback called" print "Data Received: %s" % s def e(f): print "Errorback Called" print "Error Type: %s" % type(f) print "Traceback" f.printTraceback() print "=======================================" f.trap(NonFatalError) return "Error Handled" def e_fatal(f, d): print "Errorback Called" print "Error Type: %s" % type(f) print "Traceback" f.printTraceback() print "=======================================" print "Fatal Error" f.trap(FatalError) return "Fatal Error... Crash and die. No more callbacks should be called." def trigger(): d.errback(FatalError("This error is fatal to the defer")) if __name__ == "__main__": d = D() d.addErrback(e) d.addErrback(e_fatal, d) d.addCallback(c) d.addCallback(c) d.addCallback(c) d.addCallback(c) reactor.callLater(3, trigger) reactor.callLater(10, reactor.stop) reactor.run() raw_input("Done.") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload