-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incomplete traceback with exec
on SyntaxError
#74681
Comments
The following code is supposed to catch and report errors encountered during the execution of a (python) script:
However, depending on the nature of the error, the traceback may contain the location of the error within the executed The attached tarball contains both the above as well as a 'script' that exhibit the problem. Is this a bug or am I missing something ? Are there ways to work around this, i.e. determine the correct (inner) location of the error ? (I'm observing this with both Python 2.7 and Python 3.5) |
exec
exec
on SyntaxError
Some further experiements: Replacing the
exhibits the same behaviour. If I remove the |
Answering my own question: It appears I can get the location of a syntax error by inspecting the |
The traceback contain the location of the code that raised an exception when executed. In case of NameError this is a line in your script "x=u". In case of SyntaxError the code that failed is not in your script (it still is not executed), but in a compiler implicitly called by exec(). The line with exec() is correctly reported. The behavior looks correct to me. |
OK, fair enough, that makes sense. As I said, in my last message, I was mainly simply trying to figure out the exact location of the error in the executed script, which I got from inspecting the SyntaxError. Many thanks for following up. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: