[Twisted-Python] deferred

Jp Calderone exarkun at intarweb.us
Tue Dec 2 17:43:05 EST 2003

On Tue, Dec 02, 2003 at 04:56:12PM -0500, vicky lupien wrote:
> I have a problem with deferred.  I have a wmfactory that return the
> results of a sql query but sometimes it occurs that the result is an
> sql-exception error because it's an insert query and sometimes the data
> are already in the database. When this kind of error occurs, the page is
> not render and I got an error.

  Add an errback to the deferred which handles the error in the way you
would like.  For example,

    from twisted.python import log
    def ebSQLInsert(failure):
        failure.trap(MySQLdb.IntegrityError)   # Only handle one error type
        return "The SQL insert failed"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031202/c7f6b2bf/attachment.pgp 

More information about the Twisted-Python mailing list