Resuming a program's execution after correcting error
MonkeeSage
MonkeeSage at gmail.com
Thu Sep 28 14:49:00 EDT 2006
Georg Brandl wrote:
> As I said before, this can be done by finding out where the error is raised,
> what the cause is and by inserting an appropriate try-except-statement in
> the code.
I could be mistaken, but I *think* the OP is asking how to re-enter the
stack at the same point as the exception exited from and continue with
the execution as if the exception never happened. AFAIK, that isn't
possible; however, given that he has a file to work from that indicates
a portion of the state at the time of the exception, I think he may be
able simulate that kind of functionality by reading in the file on
exception and then returning a call to the function where the exception
occured with the data from the file. Something like this mockup:
def faulty_function(a, b, c=None):
if not c:
c = 0
try:
# modify c, write c to file...
# oops hit an exception
c += a / b
except:
# read from the file here
# c = ...
# and fix the error
b += 1
return faulty_function(a, b, c)
return c
print faulty_function(2, 0) # => 2
Of course, it's probably much better to just fix the code and avoid the
exception in the first place. ;)
Regards,
Jordan
More information about the Python-list
mailing list