Stack trace

From Wikipedia, the free encyclopedia
  (Redirected from Backtrace)
Jump to: navigation, search

In computing, a stack trace (also called stack backtrace[1] or stack traceback[2]) is a report of the active stack frames at a certain point in time during the execution of a program.

Programmers commonly use stack tracing during interactive and post-mortem debugging. End-users may see a stack trace displayed as part of an error message, which the user can then report to a programmer.

A stack trace allows tracking the sequence of nested functions called - up to the point where the stack trace is generated. In a post-mortem scenario this extends up to the function where the failure occurred (but was not necessarily caused). Sibling function calls do not appear in a stack trace.

As an example, the following Python program contains an error.

1  def a():
2      b()
4  def b():
5      c()
7  def c():
8      error()
10 a()

Running the program under the standard Python interpreter produces the following error message.

Traceback (most recent call last):
  File "", line 10, in <module>
  File "", line 2, in a
  File "", line 5, in b
  File "", line 8, in c
NameError: global name 'error' is not defined

The stack trace shows where the error occurs, namely in the c function. It also shows that the c function was called by b, which was called by a, which was in turn called by the code on line 10 (the last line) of the program.

Language support[edit]

Many programming languages, including Java and C#, have built-in support for retrieving the current stack trace via system calls. C++ has no built-in support for doing this, but C++ users can retrieve stack traces with (for example) the stacktrace library. In JavaScript exceptions hold stack property that contain the stack from the place where it was thrown.

See also[edit]


  1. ^ "libc manual: backtraces". Retrieved 8 July 2014. 
  2. ^ "traceback — Print or retrieve a stack traceback". Retrieved 8 July 2014.