john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

twisted errback exceptions

ERROR HANDLING


def handle_twisted_error( failure ):
    e = failure.trap( ValueError )
    print "Invalid arguments have been passed" # or a special handle this user error function


d = asynchronous_operation()
d.addErrback( handle_twisted_error )

# note that if it's not trapped it will just pass the failure (i.e. probably stack trace)

try:
    synchronous_operation()
except UserError as e:
    handle_error(e)





RERAISE

try:
    synchronous_operation()
except:
    handle_error()
    raise




# Ensure to log errors; if it's not garbage collected and no explicit errback it won't be logged
from twisted.python import log
d.addErrback(log.err)

  • « Mysql non interactive truncate variables
  • ruby get »

Published

Sep 6, 2013

Category

python-twisted

~77 words

Tags

  • errback 2
  • exceptions 4
  • python 180
  • twisted 20