[Zope] Trapping zope exceptions in python script

Jonathan dev101 at magma.ca
Thu Dec 15 08:03:22 EST 2005


----- Original Message ----- 
From: "J Cameron Cooper" <zope-l at jcameroncooper.com>
To: "Jonathan" <dev101 at magma.ca>
Cc: <zope at zope.org>
Sent: Wednesday, December 14, 2005 4:33 PM
Subject: Re: [Zope] Trapping zope exceptions in python script


> Jonathan wrote:
>> Thanks to everyone for the feedback... the bottom line seems to be that 
>> you can NOT trap zope exceptions in a python script... which seems a bit 
>> odd.
>
> Of course you can. You just are restricted from importing certain things, 
> which happens to include this class of exception. Probably it is safe for 
> Zope to allow importing this in restricted code; feel free to file a bug 
> report.
>
> But you have easy avenues to deal with this: either declare that class 
> safe for import or take a couple extra seconds and write it in an External 
> Method.
>

Yes I know I can "force" python scripts to allow zExceptions, and yes I know 
that I can write an external method, but that was not the question.

It seems strange that one can, using plain vanilla python scripts,  trap 
bare 'try/excepts' (and I agree with Andreas that this is not a good thing 
to do!) and that one can trap python built-in exceptions, but that one 
cannot trap zope exceptions.  Why allow python scripts to trap zope 
exceptions using a bare try/except (and then have to re-raise everything 
except the target zope exception), but not allow python scripts to target 
specific zope exceptions?  I don't see the reasoning behind this approach.

I don't think this is a bug, it is more of a feature request and does 
anybody else think it is reasonable/logical/useful?

Just curious is all.

Jonathan





More information about the Zope mailing list