[Zope-dev] ZPatterns: catching exceptions raised by triggers

Steve Alexander steve@cat-box.net
Sat, 06 Jan 2001 00:49:29 +0000


Let's say I have a trigger that is called to ensure that what something 
is changed to holds true.

I use some skinscript like this:

WHEN OBJECT ADDED, CHANGED CALL self.ensure_conditions_hold()


I write the ensure_conditions_hold method so that it returns None if 
everything is ok, but raises an exception if there is a problem with the 
new state of the object.

That's all fine. However, I want to catch this exception in my 
application, and handle it in a friendly way. However, I've tried using 
dtml-try blocks and try: except: blocks from Python Scripts, and either 
way, I cannot catch the exception. It still causes Zope to return the 
standard_error_message screen.

I can only speculate that this is all due to the way that triggers get 
executed at the end of transaction. I guess I'll have to validate the 
data twice if I want to provide helpful feedback to the user.


Stranger still, the error message is reporting itself to have a strange 
content-type, so my browser is asking me if I want to download it as a 
file; I'm pretty sure this isn't related to the skinscript though, as I 
can get the same effect with other errors.

How do I catch an error raised by a Trigger?

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net