Edgewall Software

Exceptions

In programming exceptions are conditions of the program that require special processing. Handling exceptions is important, because to the user the program should function as if it were in a normal state whereby any exceptions that are encountered are handled in the background. See also Exception_handling.

This page lists the most common exceptions in Trac core and database communication.

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.

Database Exceptions

We can catch Python DB API exceptions in a database 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

Last modified 5 years ago Last modified on Sep 16, 2019, 8:15:02 PM
Note: See TracWiki for help on using the wiki.