[Zope3-dev] Please, no bare 'except:' clauses!
Steve Alexander
steve@cat-box.net
Mon, 11 Nov 2002 15:18:55 +0000
> 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
This poses a problem when you want to use ordinary python code with the
ZODB. If the code wants to catch exceptions, it has either to be very
specific about what exceptions it catches, or to be aware of the
DatabaseError type that it should not catch.
I guess the designers of Java tried to draw this kind of distinction
when making the broad divisions of
Throwable
| |
Error Exception
|
RuntimeException
(Do I have that right? It's been a while...)
All exceptions are Throwable.
Error-derived exceptions are things that the VM raises, for example,
MemoryErrors.
Exceptions are part of the compile-time type-checking system, unless
they are RuntimeExceptions.
When writing regular Java code, you shouldn't catch Throwables or Errors
unless you really know what you are doing.
In our case, ZODB errors should be the equivalent of Errors. These are
not the responsibility of applications, but are the responsibility of
the "framework"... the plumbing... etc. of which the VM is the lowest level.
--
Steve Alexander