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

    env = {}
    with open('script') as f:
        exec(, env)
    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(, 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:

Python tracker <>
Python-bugs-list mailing list

Reply via email to