[Zope3-dev] Please, no bare 'except:' clauses!

Barry A. Warsaw barry@zope.com
Mon, 11 Nov 2002 10:36:57 -0500


>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:

    |   txn = a_bdb_transaction()
    |   ok = 0
    |   try:
    |     val = do_some_work()
    |     ok = 1
    |   finally:
    |     if ok:
    |       txn.commit()
    |     else:
    |       txn.abort()
    |   return val

I find that less readable. :/ Also, I like to try to minimize the work
done in a finally clause, limiting them to things like closing an open
resource.  Committing and aborting the underlying transaction doesn't
quite feel like the same thing to me.

Whoever said Python straightjackets programmers anyway? :)

    >> - In a framework,

    GvR> What's a framework?  "Framework" is one of those words that
    GvR> mean whatever you wish it to mean. :-)

Which is why I used it! :)

    GvR> The common characteristic seems to be that these take
    GvR> external descriptions of some work to be done, and they
    GvR> should report success or failure, plus details like output or
    GvR> traceback.  RPC servers typically also do this: any
    GvR> exceptions raised by an incoming call should be caught and
    GvR> propagated to the client, rather than killing the RPC server.

Right!  Cgis should do the same thing, because if the exception exits
the program, the web server will return a less friendly error page.

    >> I'm sure others can come up with more useful patterns and
    >> antipatterns.  Perhaps PEP 8 would be a good place to document
    >> recommendations.

    GvR> +1 as long as I don't have to write it (I'll review it :-).

Me too, me too. :)

-Barry