Skip to content

Exceptions & error codes

The exception hierarchy is per PEP 249. All exceptions live in informix_db and inherit from informix_db.Error.

Error
├── Warning
└── DatabaseError
├── InterfaceError
├── DataError
├── OperationalError
│ └── PoolTimeout
├── IntegrityError
├── InternalError
├── ProgrammingError
└── NotSupportedError
ExceptionTypical cause
InterfaceErrorMisuse of the driver API itself (e.g. fetch on a closed cursor).
DataErrorType conversion failures, codec errors.
OperationalErrorNetwork errors, timeouts, server unavailable, login failures.
IntegrityErrorConstraint violations (PK, FK, unique, NOT NULL).
InternalErrorDriver-internal invariant violation (file a bug).
ProgrammingErrorBad SQL syntax, missing tables, parameter binding errors.
NotSupportedErrorDriver doesn’t support the requested operation.
PoolTimeoutPool acquire exceeded acquire_timeout.

Informix returns SQLCODE values; the driver maps them to the appropriate exception. A few common ones:

SQLCODEMeaningException
-201Syntax errorProgrammingError
-206Table not foundProgrammingError
-239 / -268 / -691 / -703Unique / FK / NOT NULL violationIntegrityError
-329Database not foundOperationalError
-908Connection terminated by serverOperationalError
-1820Codeset conversion failureDataError
-908 / network errorsServer unavailableOperationalError

The full mapping lives in src/informix_db/_errcodes.py.

Every exception carries the original SQLCODE and message:

try:
cur.execute("INSERT INTO users VALUES (?, ?)", (1, "alice"))
except informix_db.IntegrityError as e:
print(e.sqlcode) # -239 (unique violation)
print(e.isam_code) # secondary error code
print(str(e)) # human-readable

sqlcode is the primary error; isam_code is the underlying ISAM error (when applicable). For multi-statement transactions, use e.statement to see which statement failed.