[Zope-CMF] Re: [dev] some questions regarding Exceptions

Dieter Maurer dieter at handshake.de
Tue Sep 16 14:40:59 EDT 2003


Yuppie wrote at 2003-9-16 12:59 +0200:
 > ...
 > After rereading the python docs, I think the root exception has to be
 > 
 >    class CMFError(Exception):
 > 
 > Thats the easy part.

I do not think, it should derive from "Exception" but from
"StandardError".

There are exceptions that are not errors, e.g. ConflictError.
It should be easy to catch just errors with "except StandardError"
and let non-error exceptions through.


This is widely not adhered, too, but we may start with it.

 > For the hierarchy I see two possible approaches:
 > 
 > a) by type (CMFValueError, CMFUnauthorizedError, ...)

I do not think I am in any way interested whether
a "ValueError" is a "CMFValueError" or a "non-CMFValueError".
Same for "Unauthorized".

Note, that exceptions should be catched only in exceptional
circumstances. Catching exceptions (without reraising this
or raising another exception) is dangerous as the ZODB
might be in an inconsistent state which may be committed
when the exception is swallowed.

Therefore, I would argue: keep the exception hierarchy simple.
Define a new class only, when you know that someone could
safely catch it and could not without the additional class.

 > b) by module/context (MembershipError, MetadataError, ...)

This may make end user error messages a bit easier to generate.
However, I did not yet feel such a requirement.



Dieter



More information about the Zope-CMF mailing list