Installation guide
mxODBC - Python ODBC Database Interface
10. mxODBC Exceptions and Error
Handling
The mxODBC package and all its subpackages use the DB API 2.0 exceptions
layout. All exceptions are defined in the submodule
mx.ODBC.Error but also
imported into the top-level package module
mx.ODBC as well as all sub-packages.
Note that all sub-packages use the same exception classes, so writing cross-
database applications is simplified this way.
The exception values are either
• a single string, or
• a tuple having the format
(sqlstate, sqltype, errortext, lineno)
SQL state (
sqlstate) and type (sqltype) are defined by the ODBC standard and
may be extended by the specific ODBC driver handling the connection. Please see
the ODBC driver manual for details.
lineno refers to the line number in the
mxODBC.c file to ease debugging the package.
Note on the mx.ODBC.Error Module
If you want to import the exception classes from the
mx.ODBC.Error submodule,
you have to use the
from…import form:
from mx.ODBC.Error import ProgrammingError
The reason is that the Error base class is imported into the top-level mx.ODBC
package when loading it, shadowing the module of the same name. With the
above form, Python will lookup
mx.ODBC.Error in the module dictionary instead
of the
mx.ODBC package and find the module instead of the mx.ODBC.Error
exception class.
10.1 Exception Classes
These exceptions are defined in the modules scope and also available as attributes
of the connection objects to easy writing applications using different mxODBC
sub-packages.
Error
Baseclass for all other exceptions related to database or interface errors.
You can use this class to catch all errors related to database or interface
failures.
error is just an alias to Error needed for DB-API 1.0 compatibility.
158