Edgewall Software

Version 8 (modified by Ryan J Ollos, 9 years ago) ( diff )

Changes to hierarchy from #11568.


Custom Trac Exceptions

Trac defines a set of custom exception types:

Hierarchy is inconsistent, even after addition of TracBaseError class (#11568). There doesn't seem to be any consistent pattern in inheriting from TracError. Some exceptions also inherit from built-in exception classes other than Exception.

There also seem to be multiple naming conventions. Consider following PEP:0008#exception-names.

But changing the existing hierarchy might be difficult without breaking backward compatibility.

DB Exceptions

We can catch Python DB API exceptions in a DB-neutral way. (Since Trac 1.0, see #6348.)

    with env.db_transaction as db: 
except env.db_exc.IntegrityError, e: 

The above example catches sqlite.IntegrityError, MySQLdb.IntegrityError or psycopg.IntegrityError, depending on the selected DatabaseBackend.

See tickets

Note: See TracWiki for help on using the wiki.