Edgewall Software

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

Document MacroError. Refs #12359.

Exceptions

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

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.