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)