[Zope3-dev] Please, no bare 'except:' clauses!
Barry A. Warsaw
barry@zope.com
Mon, 11 Nov 2002 10:08:55 -0500
>>>>> "CD" == Casey Duncan <casey@zope.com> writes:
>> I still think this is a good future goal.
CD> Ok then, so that makes my point moot. I still think it would
CD> be nice if there was a way for database errors to propagate
CD> through application code, but it sounds like user education is
CD> the only real answer.
But if the three main subsystems you outlined each defined their own
base exception class (deriving from Exception), and application code
made sure to catch only the derived classes, I think you could largely
stil accomplish this goal.
class DatabaseError(Exception):
"Derive all ZODB exceptions from this class"
class ZopeError(Exception):
"Derive all Zope framework exceptions from this class"
class AppError(Exception):
"Each application should derive its own base exception from this class"
try:
except DatabaseError: # All ZODB/transactional errors (conflicts, etc)
except ZopeError: # All Zope framework exceptions
except AppError: # All application defined exceptions
except Exception: # All Python exceptions
-Barry