[Tutor] capturing exceptions from an exec statement
Alan Gauld
alan.gauld at btinternet.com
Tue Apr 8 10:48:38 CEST 2008
"Andreas Kostyrka" <andreas at kostyrka.org> wrote
>>> try:
>... exec("raise ValueError")
>... except:
>... print "raised some exception"
>... import sys
>... print sys.exc_info()
>...
>raised some exception
>(<class exceptions.ValueError at 0xb7d83b3c>, <exceptions.ValueError
>instance at >0xb7d6738c>, <traceback object at 0xb7d65aa4>)
>
>Something like this?
I think the Gary means he wants an exception raised if the code
fed to exec is invalid, not if the code raises an exception.
But exec seemed to raise all the usual errors in the cases I tried.
Gary, can you give us a concrete example of the kind of error
you expect but don't see?
Also, I don't know if you have come across the cmd module
but it might be useful in this context...
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list