[Zope] Trapping zope exceptions in python script

Nikko Wolf nikko-wolf at earthlink.net
Wed Dec 14 14:54:56 EST 2005


Jonathan wrote:
> I am trying to catch a 'BadRequest' exception in the following python 
> script excerpt:
> 
> for item in itemList:
>   try:
>      context.afolder.manage_delObjects([item])
>   except BadRequest:
>      continue


> NameError: global name 'BadRequest' is not defined

The following would normally be required, but it fails with an ImportError:

    from zExceptions import BadRequest

So you could try this instead:

    for item in itemList:
       try:
          context.afolder.manage_delObjects([item])
       except:
          continue

In general, TTW coding is very limited; you can use External Methods 
(a.k.a. Extensions) or Products to avoid this.



More information about the Zope mailing list