[Zope] Search a Catalog in Python

Dieter Maurer dieter at handshake.de
Wed Mar 17 18:36:56 EST 2004


Max M wrote at 2004-3-16 18:50 +0100:
> ...
>This approach should be failsafe
>
>result = []
>for brain in brains:
>     try:
>         obj = brain.getObject()
>         result.append(obj)
>     except: # Will probably raise AttributeError on None object
>         pass

You are proposing here a so called "bare" "try ... except".

Such "try ... except"s are wide spread in the Zope sources.
They have been the cause of many many difficult to analyse
problems. Therefore, they are considered bad.

The best approach is not to catch exceptions at all (and handle
them in your "standard_error_message").

When you know that some exceptions are not real exceptions
you can catch *precisely* these exceptions.
There are really few occasions where you can be sure that
*any* exception is not a real exception...

-- 
Dieter



More information about the Zope mailing list