Resuming a program's execution after correcting error
Sheldon
shejo284 at gmail.com
Tue Oct 3 10:44:39 EDT 2006
MonkeeSage wrote:
> 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
Thanks Jordon,
I think you understood my problem best. I know now that this is not
possible but I would like to create an exception that saves all the
current variables when there is an error. I think pickle is the answer
but I never got it to work. My program is very large and it is being
modified often.
Any advice on how to save the variables.
/Sheldon
More information about the Python-list
mailing list