mxODBC error trapping

Paul Boddie paulb at infercor.no
Wed Apr 26 12:31:17 CEST 2000


Joshua Macy wrote:
> 
> "Daley, MarkX" wrote:
> >
> > Traceback (innermost last):
> >   File "<pyshell#1>", line 1, in ?
> >     collect.collect()
> >   File "C:\PROGRA~1\Python\collect.py", line 50, in collect
> >     except dbi.OperationalError:
> > AttributeError: OperationalError
> >
> > Here is the printout of the dbi module:
> >
> > ['DATE', 'NUMBER', 'RAW', 'ROWID', 'STRING', 'TYPES', '__doc__', '__file__',
> > '__name__', 'dataError', 'dbDate', 'dbRaw', 'dbiDate', 'dbiRaw',
> > 'integrityError', 'internalError', 'noError', 'opError', 'progError']
> 
>   According to the dbi module dictionary (which you've printed), it
> looks like it should be opError, not OperationalError.  Or you could
> just use an unqualified except, and be sure of catching any error that
> the dbi can raise.

You should be looking in the module where the 'connect' function was defined.
So, if you used 'ODBC.iODBC.connect' to connect to the database, you will find
that 'OperationalError' is defined in 'ODBC.iODBC' too:

>>> dir(ODBC.iODBC)
['BIGINT', 'BINARY', 'BIND_USING_PYTHONTYPE', 'BIND_USING_SQLTYPE', 'BIT',
'CHAR', 'Connect', 'DATE', 'DATETIME_DATETIMEFORMAT', 'DECIMAL', 'DOUBLE',
'DataError', 'DatabaseError', 'DriverConnect', 'Error', 'FLOAT', 'INTEGER',
'IntegrityError', 'InterfaceError', 'InternalError', 'LONGVARBINARY',
'LONGVARCHAR', 'NUMERIC', 'NotSupportedError', 'OperationalError',
'ProgrammingError', 'REAL', 'SMALLINT', 'SQL', 'STRING_DATETIMEFORMAT', 'TIME',
'TIMESTAMP', 'TIMEVALUE_DATETIMEFORMAT', 'TINYINT', 'TUPLE_DATETIMEFORMAT',
'VARBINARY', 'VARCHAR', 'Warning', '__builtins__', '__doc__', '__file__',
'__name__', '__path__', '__version__', 'apilevel', 'connect', 'error',
'errorclass', 'mxODBC', 'mxODBCType', 'mxODBCursorType', 'paramstyle',
'sqltype', 'threadlevel']

It would be "expected" that errors and exceptions were defined in the same
module as the classes and functions, but I suppose the structure of mxODBC makes
this assumption a little uncertain. Still, 'dir' used liberally often tells you
what you need to know.

Paul



More information about the Python-list mailing list