[IPython-dev] Continuing from an exeption

Fernando Perez fperez.net at gmail.com
Thu Nov 22 16:11:51 EST 2007


On Sep 20, 2007 1:21 PM, Gael Varoquaux <gael.varoquaux at normalesup.org> wrote:
> OK, this is a stupid question ,the answer is probably somewhere in the
> manual, and the question should be asked on the user mailing list. But...
>
> How can I continue running a script after it bailed out because of an
> exception ?
>
> For instance I have
>
> """
> b = do_long_calculation()
> print a
> a = other_long_calculation(b)
> """
>
> This will fail because a does not exist. I can "%debug" to go in debug
> mode and find that out. I could correct the problem by defining a, and
> then continue the script, or I could just decide to skip the line and
> continue the script.
>
> Is there a way to do this ?

No, the python language doesn't really support execution resumption
after an exception.  I imagine one could hack up something very nasty
that would involve an exec-like function that takes the existing stack
and restarts it with modified pointers to new code, but it's not
anything that I've seen done, nor that I plan on writing anytime soon
:)

Cheers,

f



More information about the IPython-dev mailing list