[DB-SIG] what's wrong with an exception-catching class?

Jim Hefferon jim@joshua.smcvt.edu
Wed, 27 Nov 2002 15:26:30 -0500


   > Chris Cogdon wrote:
   >>> This is why I feel that there is no 'standard library' for catching 
   >>> exceptions, because the 'correct' thing for any particular 
   >>> application varies widely and wildly between applications.

But then how do I avoid having the outer level in my programs filled
with many 30-line try: .. except DataError .. except OperationalError ...
sections?  

I want to refactor, to write that once and have it done right, so
I thought to do a dbOp object that encapsulates the behavior.  But I
can't see why I've not found discussion of that encapsulation. 

   > Magnus Lycka wrote:
   If you write programs like so:

   # Change this line if you port to another DB-API wrapper:
   import myDBwrapper as dbapi

   ...
   try:
       cursor.execute(...)
   except dbapi.Error, why:
       print 'Ooops: %s' % why

   you pretty much get what you want.

So is this DB-API wrapper what I am writing?  Because that section of
code is what I now have at my outer layer.  Has this been discussed here 
previously, or are there examples of such wrappers in archives, and I have
just not been able to find them?

Thanks for the help,
Jim