[Zope] Another Python Script Question

Tim Zegir trzegir at ncable.net.au
Thu Dec 4 21:44:59 EST 2003


Well its getting closer.

If I use this

For object in context.myscript
  Try:
     Context.myscript2
  Except:
    Try:
       Print error
    except NameError, e:
         print e
return e

I catch the 'print error' error (because it is not defined) NOT the
original try error.

If I use 

for object in context.myscript:
   try:
      context.myscript2
   except NameError, e:
         print e
return printed

it does not catch the error at all and brings up the default zope error
message.

If I use

for object in context.myscript:
   try:
      context.myscript2
   except:
         print 'an error has happoned'
return printed

I get the behaviour I want but without the error description :)

Thank you all for your help so far.


-----Original Message-----
From: Dan Pierson [mailto:dan at control.com] 
Sent: Friday, 5 December 2003 1:21 PM
To: Tim Zegir
Subject: RE: [Zope] Another Python Script Question

Look in a Python manual :-)

The try statement is as follows:

try:
   something
except <exception type>, <var to hold exception info>:
   exception handling code

E.G.:

try:
   print error
except NameError, e:
   print e

Which will print the error you just got...

Unfortunately, except without an exception type doesn't
let you get info on the exception.  This isn't really too
bad because you should use "naked excepts" VERY rarely --
usually at the top level of a UI, because they are likely
to catch things you really didn't want to catch.  You should
usually understand what the expected exception types are
and catch them explicitly.

On Thu, 2003-12-04 at 20:42, Tim Zegir wrote:
> Yes it works.... sort of
> I now get this error
> 
> Error Type: NameError
> Error Value: global name 'error' is not defined
> 
> So I guess error is not the right object to use??
> 
> 
> -----Original Message-----
> From: James Davies [mailto:jamesd at mena.org.au] 
> Sent: Friday, 5 December 2003 12:12 PM
> To: Tim Zegir; zope at zope.org
> Subject: Re: [Zope] Another Python Script Question
> 
> for item in object:
> 	try:
> 		context.somescript()
> 	except:
> 		print error
> return printed
> 	
> 
> On Fri, 5 Dec 2003 10:51 am, Tim Zegir wrote:
> > How would I go about using a statement like 'on-error' in a python
> > script?
> > Eg.
> > For item in object:
> >             context.somescript
> >             on-error:
> >                         print error
> >                         skip
> > return printed
> >
> > Thanks
> > Tim Zegir
> 
> 
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
-- 
Dan Pierson <dan at control.com>







More information about the Zope mailing list