[Tutor] try except continue
Ewald Ertl
ewald.ertl at hartter.com
Fri Jul 29 10:02:08 CEST 2005
Hi!
I think you just want to execute the rest of the function's in someProcedure().
Perhaps this could be the solution, what you want:
>>> def someProcedure():
... for func in [ someFunc00, someFunc01, someFunc02, someFunc03 ]:
... try:
... func()
... except:
... print "Error in %s " % ( func.__name__ )
... continue
...
>>>
>>> someProcedure()
Error in someFunc00
yeah!
baby let's go
someInt is: 4
HTH Ewald
tpc at csua.berkeley.edu wrote:
> hey guys, so I've been trying to get my head around the try except
> statement in Python, and ideally what I'd like is for my procedural
> program, when it runs through its steps and encounters an error, to log
> the error and pick up where it left off and keep going. According to this
> link, 'continue' is allowed within an except or finally:
>
> http://python.active-venture.com/ref/continue.html
>
> I tried to run the following code, expecting to catch a NameError and
> continuing on:
>
> def someFunc00():
> someModulo = 6%2
> print someModulus
>
> def someFunc01():
> print "yeah!"
>
> def someFunc02():
> print "baby let's go"
>
> def someFunc03():
> someInt = 2+2
> print "someInt is: ", someInt
>
> def someProcedure():
> someFunc00()
> someFunc01()
> someFunc02()
> someFunc03()
>
> # copy and paste the following into IDLE, which on my machine often
> #crashes for an unknown reason, so I've taken to creating a harness that
> #imports the required library and then runs the desired programs to test
> #the desired behavior
> if __name__ == "__main__":
> import testTryCatch
> try:
> testTryCatch.someProcedure()
> except:
> print "encountered error"
> continue
>
> but I get the following error:
>
> SyntaxError: 'continue' not properly in loop
>
> What am I doing wrong ?
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list