def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
error = errorclass, errorvalue<EOL>if cursor:<EOL><INDENT>cursor.messages.append(error)<EOL><DEDENT>else:<EOL><INDENT>connection.messages.append(error)<EOL><DEDENT>del cursor<EOL>del connection<EOL>raise errorclass(errorvalue)<EOL>
If cursor is not None, (errorclass, errorvalue) is appended to
cursor.messages; otherwise it is appended to
connection.messages. Then errorclass is raised with errorvalue as
the value.

You can override this with your own error handler by assigning it
to the instance.