Re: Resuming a program's execution after correcting error
- From: "MonkeeSage" <MonkeeSage@xxxxxxxxx>
- Date: 28 Sep 2006 11:49:00 -0700
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
.
- References:
- Resuming a program's execution after correcting error
- From: Sheldon
- Re: Resuming a program's execution after correcting error
- From: Georg Brandl
- Resuming a program's execution after correcting error
- Prev by Date: Re: Can string formatting be used to convert an integer to its binary form ?
- Next by Date: Re: preemptive OOP?
- Previous by thread: Re: Resuming a program's execution after correcting error
- Next by thread: Re: Resuming a program's execution after correcting error
- Index(es):
Relevant Pages
|