[New-bugs-announce] [issue30496] Incomplete traceback with `exec`

Stefan Seefeld report at bugs.python.org
Sun May 28 09:28:54 EDT 2017


New submission from Stefan Seefeld:

The following code is supposed to catch and report errors encountered during the execution of a (python) script:

```
import traceback
import sys

try:
    env = {}
    with open('script') as f:
        exec(f.read(), env)
except:
    type_, value_, tb = sys.exc_info()
    print (traceback.print_tb(tb))
```
However, depending on the nature of the error, the traceback may contain the location of the error *within* the executed `script` file, or it may only report the above `exec(f.read(), env)` line.

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)

----------
files: pyerror.tgz
messages: 294645
nosy: stefan
priority: normal
severity: normal
status: open
title: Incomplete traceback with `exec`
type: behavior
Added file: http://bugs.python.org/file46908/pyerror.tgz

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30496>
_______________________________________


More information about the New-bugs-announce mailing list