Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retry after a crash possible?

Status
Not open for further replies.

leegold2

Technical User
Oct 10, 2004
116
Hi,

Is there a way to do the following? Using Python 2.1,

Say I have a WHILE loop. Inside the WHILE there's code that reads and processes lines of data. About one out of ten times (ie. sometimes) there's a data record that causes a crash and the program terminates. I can put a try/except and the error message is catched when program terminates.

But is there a way to keep looping through the data?

One choice is to filter the bad crashing lines w/IF-THEN and only process stuff in the WHILE that won't crash it.

BUT, is there another way? Like a "retry" or "recover" that says something like: "Yeah you crashed the script with this nasty line of data, but I'm going back into the loop and will continue process the next line and do this until EOF."

It'd have to trap the exception, keep state to a degree, and start the loop...

Is this possible?

Thanks,

Lee
 
I can put a try/except and the error message is catched when program terminates.

The try/except should allow the program to continue. For example:

Code:
try:
    <your code here>
except:
    pass # Don't crash. Just bypass the current failure.

That help?
--
ZaSter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top