Select to view content in your preferred language

Using continue in a try statement

2041
3
07-11-2012 05:41 AM
by Anonymous User
Not applicable
Original User: MCline19

Is it possible at all to use "continue" in a try statement.  I am repeatedly getting the error: "***'continue' not properly in loop([filename], line 67); however, I can not figure out how to "properly" fit it in the loop.  My current code is below.  Any help would be greatly appreciated! Thanks


try:
 print ("Beginning temporary file removal")
 for x in sdeFiles:
  n = x.split('.')[-1]
  for e in fileExtns:
   delExtns = n + e
   delFile = 'G://GISAdmin//SDE_Backups//NewTempShapefiles//' + delExtns
   os.remove(delFile)
 print ("Temporary files deleted")
except:
 print ("Error: " + extension + " does not exist")
 continue
finally:
 print ("Delete complete")
0 Kudos
3 Replies
by Anonymous User
Not applicable
Original User: mzcoyle

Once it has exited the try statement, it will not return to it. To accomplish this you would have to put your try/except inside your loop to continue executing in spite of errors.
0 Kudos
DanPatterson_Retired
MVP Emeritus
continue needs to be in a loop such as a "while" loop, it can't be used on its own
0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

Works perfectly now!  Thank you!
0 Kudos