[Tutor] try except continue
tpc@csua.berkeley.edu
tpc at csua.berkeley.edu
Thu Jul 28 19:45:02 CEST 2005
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 ?
More information about the Tutor
mailing list