Edgewall Software

Version 5 (modified by Peter Suter, 11 years ago) ( diff )

Link to tickets

Exceptions

Custom Trac Exceptions

Trac defines a set of custom exception types:

This hierarchy seems fairly inconsistent. Consider using the TracError base class consistently.

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.)

try: 
    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.