There are many sources of errors. A few examples are a syntax error in an executed SQL statement, a connection failure, or calling the fetch method for an already canceled or finished statement handle.
The DB API defines a number of errors that must exist in each database module. The following table lists these exceptions.
|Sr.No.||Exception & Description|
Used for non-fatal issues. Must subclass StandardError.
Base class for errors. Must subclass StandardError.
Used for errors in the database module, not the database itself. Must subclass Error.
Used for errors in the database. Must subclass Error.
Subclass of DatabaseError that refers to errors in the data.
Subclass of DatabaseError that refers to errors such as the loss of a connection to the database. These errors are generally outside of the control of the Python scripter.
Subclass of DatabaseError for situations that would damage the relational integrity, such as uniqueness constraints or foreign keys.
Subclass of DatabaseError that refers to errors internal to the database module, such as a cursor no longer being active.
Subclass of DatabaseError that refers to errors such as a bad table name and other things that can safely be blamed on you.
Subclass of DatabaseError that refers to trying to call unsupported functionality.
Your Python scripts should handle these errors, but before using any of the above exceptions, make sure your MySQLdb has support for that exception. You can get more information about them by reading the DB API 2.0 specification.