This function defines custom exceptions for MySQL server errors and returns current customizations.
If error is a MySQL Server error number, then
you have to pass also the exception class.
The error argument can also be a dictionary
in which case the key is the server error number, and value the
class of the exception to be raised.
To reset the customizations, simply supply an empty dictionary.
import mysql.connector
from mysql.connector import errorcode
# Server error 1028 should raise a DatabaseError
mysql.connector.custom_error_exception(1028, mysql.connector.DatabaseError)
# Or using a dictionary:
mysql.connector.custom_error_exception({
1028: mysql.connector.DatabaseError,
1029: mysql.connector.OperationalError,
})
# To reset, pass an empty dictionary:
mysql.connector.custom_error_exception({})

User Comments
Add your own comment.