[Zope-DB] How to I handle the DataBase Errors ?

Dieter Maurer dieter at handshake.de
Fri Jul 9 13:38:37 EDT 2004


fowlertrainer at anonym.hu wrote at 2004-6-30 09:20 +0200:
>When I start a webpage that uses many ZSQL methods, and the DataBase
>have been shutted down, I get Zope default error.
>But how to I redirect this message to my own error page ?
>
>ok, response.redirect()
>
>but how to I determine that this problem caused by DataBase error ?
>
>I don't want to replace every ZSQL call from:
>
>myrows=context.myzsql(params)
>
>to:
>
>myrows=context.callmyzsqls(context.myzsql,params)
>
>def callmyzsqls(azsql,aparams):
>    try:
>       result=azsql(params)
>    except:
>       text=getexceptiontext()
>       response.redirect('/databaseerror')

You should never do this!

  "try: ... except: ..." is very (!!!) dangerous in
  a system with persistent data (in ZODB or RDBMS).
  Catching the exception may result in an inconsistent
  persistent state.

The best way is not to catch exceptions but handle exceptions
in a customized "standard_error_message".

-- 
Dieter


More information about the Zope-DB mailing list