Hi, We have a lot of Python code in .py files run via External Methods for an application we are developing. I have a bit of a dilema about the exception handling. I find that if I catch exceptions in the External Methods (so that I can display a nice error page to the user) nothing is logged to the Site Error log. If I remove all try-exception blocks from the code any errors throw up the standard Zope error page and log to the Site Error Log. Is there a way to show the user a custom error page and still have the error logged to the Site Error Log? Tim Edwards Trainee Analyst Programmer Henry Walker Eltin Phone: 02 9887 6393 Email: tim.edwards@hwe.com.au
Tim Edwards wrote at 2004-4-22 12:28 +0800:
We have a lot of Python code in .py files run via External Methods for an application we are developing. I have a bit of a dilema about the exception handling. I find that if I catch exceptions in the External Methods (so that I can display a nice error page to the user) nothing is logged to the Site Error log. If I remove all try-exception blocks from the code any errors throw up the standard Zope error page and log to the Site Error Log.
You definitely should not catch exceptions yourself. You risk to get your databases (ZODB and relational databases) in an inconsistent state unless you raise again an exception.
Is there a way to show the user a custom error page and still have the error logged to the Site Error Log?
You customize "standard_error_message" ... -- Dieter
You definitely should not catch exceptions yourself. You risk to get your databases (ZODB and relational databases) in an inconsistent state unless you raise again an exception.
Really? Is there any more detail to this than "just don't do it". I rely on the fact that code in External Methods and full-blown Products can catch exceptions and handle them gracefully (it's one of Python's best features!!). It would hurt a lot to have to stop using them. JZ
John Ziniti wrote at 2004-4-23 11:19 -0400:
You definitely should not catch exceptions yourself. You risk to get your databases (ZODB and relational databases) in an inconsistent state unless you raise again an exception.
Really? Is there any more detail to this than "just don't do it". I rely on the fact that code in External Methods and full-blown Products can catch exceptions and handle them gracefully (it's one of Python's best features!!). It would hurt a lot to have to stop using them.
Normal Python appliciations do not manipulate persistent data. Therefore, Python's aborting exception handling may be adequate. Whenever you handle persistent data, catching exceptions (without raising this or another exception and without explicitly aborting the transaction) gives you a good chance to commit an inconsistent state. Furthermore, you must keep in mind, that Zope/ZODB uses exceptions as a way to communicate with ZPublisher -- via "ConflictError" exceptions. When you turn them into another exception, you made a harmless thing (the request would have been retried) into an error. When you ignore them, part of the operation was not executed without anyone noticing it. You should only catch an exception when both of the following conditions are met: 1. you know that the exception is not really exeptional but normal behaviour. 2. you know that the code inside the "try: ... except XXX:" has not modified persistent state (or you abort the transaction explicitly) Usually, you know this only for a few well defined exceptions. Most exceptions are truely exceptional and must not be catched. "ConflictError" definitely must not be catched. -- Dieter
participants (3)
-
Dieter Maurer -
John Ziniti -
Tim Edwards