mardi 30 juin 2015

How do you catch exceptions during class loading

I have a SQLite database and use SQLAlchemy to map the tables to classes. The generate layout is that I have a parent table and a child table. A Parent class may have multiple children, and a Child only one parent. The children are loaded into a custom collection class for various pre and post processing.

There are times that an exception may be raised during the loading of the Child class. This is somewhat abnormal operation, usually due to database corruption or an exceedingly old database, but it does require intervention. However I don't seem to have any way of catching this exception.

As a work around, I assume that instead of raising an Exception, I could flag the class with a self.delete = True and check for this when loading into the collection class. But it still begs the question about what to do about exceptions that may raise during loading of a class from the database mapper?

Aucun commentaire:

Enregistrer un commentaire