Questions tagged [traceback]

A traceback is a report of the actions leading up to a run-time error in the execution of a program.

A traceback is a report of the actions leading up to a run-time error in the execution of a program. For example, the following traceback:

Traceback (most recent call last):
  File "convert.py", line 23, in <module>
    display(literal_eval(sys.argv[1]), *sys.argv[2:])
  File "convert.py", line 16, in display
    result = convert(quantity, from_unit, to_unit)
  File "convert.py", line 10, in convert
    conversion = CONVERSIONS[from_unit, to_unit]
KeyError: ('cm', 'inch')

shows that in the Python program convert.py, the function display() was called, which in turn called the function convert(), which attempted to look up a nonexistent item with the key ('cm', 'inch') in the dictionary CONVERSIONS.

Reporting the actions leading up to an error, rather than just the line on which the error occurred, can assist in debugging a faulty program.

730 questions
35
votes
1 answer

python: Is there a downside to using faulthandler?

Python 3.3 includes a module named faulthandler that displays helpful traceback information if a segfault occurs. (For Python versions prior to 3.3, the module can be obtained from PyPI.) The module is not enabled by default. It is enabled like…
Stuart Berg
  • 17,026
  • 12
  • 67
  • 99
34
votes
5 answers

Get full traceback

How can i get full traceback in the following case, including the calls of func2 and func functions? import traceback def func(): try: raise Exception('Dummy') except: traceback.print_exc() def func2(): …
warvariuc
  • 57,116
  • 41
  • 173
  • 227
33
votes
9 answers

Remove traceback in Python on Ctrl-C

Is there a way to keep tracebacks from coming up when you hit Ctrl+c, i.e. raise KeyboardInterrupt in a Python script?
Kyle Hotchkiss
  • 10,754
  • 20
  • 56
  • 82
33
votes
2 answers

How do I use Django's logger to log a traceback when I tell it to?

try: print blah except KeyError: traceback.print_exc() I used to debug like this. I'd print to the console. Now, I want to log everything instead of print, since Apache doesn't allow printing. So, how do I log this entire traceback?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
33
votes
4 answers

traceback() for interactive and non-interactive R sessions

I observed a different between an interactive and non-interaction R session about traceback() which I do not understand. For the code below, it will produce an error, but in an interactive R session, I can see the traceback information, whereas if I…
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
32
votes
5 answers

How to format traceback objects in Python

I have a traceback object that I want to show in the nice format I get when calling traceback.format_exc(). Is there a builtin function for this? Or a few lines of code?
olamundo
  • 23,991
  • 34
  • 108
  • 149
30
votes
2 answers

How to imitate Python 3's raise ... from in Python 2?

Python 3 has the neat try: raise OneException('sorry') except OneException as e: # after a failed attempt of mitigation: raise AnotherException('I give up') from e syntax which allows raising a followup exception without loosing…
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
26
votes
3 answers

Why can't I pickle an error's Traceback in Python?

I've since found a work around, but still want to know the answer.
Trindaz
  • 17,029
  • 21
  • 82
  • 111
26
votes
8 answers

How can I log current line, and stack info with Python?

I have logging function as follows. logging.basicConfig( filename = fileName, format = "%(levelname) -10s %(asctime)s %(message)s", level = logging.DEBUG ) def printinfo(string): if DEBUG: logging.info(string) def…
prosseek
  • 182,215
  • 215
  • 566
  • 871
20
votes
1 answer

What is the type of traceback objects in Python?

import sys try: raise Exception('foobar') except: info = sys.exc_info() print(type(e[2])) # help(traceback) # NameError: name 'traceback' is not defined What exactly is the type of the traceback objects that Python…
Noah
  • 1,329
  • 11
  • 21
20
votes
3 answers

How do I can format exception stacktraces in Python logging?

The logs I am creating in Python are intended to be temporarily stored as files which will, in turn, be processed into a log database. They take a pipe-delineated format to dictate how the logs will be processed, but logging.exception() is breaking…
twoxmachine
  • 517
  • 2
  • 7
  • 16
20
votes
5 answers

How can you programmatically inspect the stack trace of an exception in Python?

When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the traceback module, but I can't figure out how to use it. My goal is to catch any exceptions that occur during the parsing of an eval…
Nick Retallack
  • 18,986
  • 17
  • 92
  • 114
20
votes
4 answers

Print stacktrace from C code with embedded lua

If I understand this correctly, Lua by default will call the debug library "debug.traceback" when an error occurs. However, when embedding Lua into C code like done in the example here: Simple Lua API Example We only have available the error message…
hookenz
  • 36,432
  • 45
  • 177
  • 286
19
votes
2 answers

How can I elide a function wrapper from the traceback in Python-3?

The issue The Phantom Menace Say i wrote a function decorator which takes the function, and wraps it in another function like so: # File example-1.py from functools import wraps def decorator(func): # Do something @wraps(func) def…
Re.po
  • 214
  • 1
  • 7
19
votes
3 answers

Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests?

I'm writing some tests with Selenium. When i run my selenium tests (LiveServerTestCase type) and i have some error in my code (not in the test, i mean in the code executed, like the homepage view i reach with selenium) i get the 500 template (that…
apelliciari
  • 8,241
  • 9
  • 57
  • 92
1
2
3
48 49