[Twisted-Python] errorhandler example in docs needs work

Reading this in the manual: http://twistedmatrix.com/documents/current/howto/defer Example of how to write error handlers for exceptions: def errorHandler(failure): failure.trap(SpamException, EggException) # Handle SpamExceptions and EggExceptions d.addCallback(cookSpamAndEggs) d.addErrback(errorHandler) This example is missing something. The #handle SpamExceptions should have at least one statement after the # like print "I am handling the exception" I look at this example above and I still don't know how to write an error handler. I shall read further, but I wanted to share my feedback.

Alan Ezust wrote:
Reading this in the manual: http://twistedmatrix.com/documents/current/howto/defer
Example of how to write error handlers for exceptions:
def errorHandler(failure): failure.trap(SpamException, EggException) # Handle SpamExceptions and EggExceptions
d.addCallback(cookSpamAndEggs) d.addErrback(errorHandler)
This example is missing something. The #handle SpamExceptions should have at least one statement after the # like print "I am handling the exception"
I look at this example above and I still don't know how to write an error handler. I shall read further, but I wanted to share my feedback.
How would the print statement help you to know how to write an error handler? Maybe there should be a "bigger" example somewhere, outside the defer howto, with real code. Something like "try to fetch this URL via HTTP, retry up to three times".

On Sun, Dec 26, 2004 at 11:24:18AM -0500, Alan Ezust wrote:
This example is missing something. The #handle SpamExceptions should have at least one statement after the # like print "I am handling the exception"
If you want to see the error (and traceback), the usual thing to do is from twisted.python import log log.err(failure)
I look at this example above and I still don't know how to write an error handler. I shall read further, but I wanted to share my feedback.
Of course the actual logic of the error handler depends on what the error means and what should be done about it, but that is somewhat application specific.... -w
participants (3)
-
Alan Ezust
-
Tommi Virtanen
-
William Waites