Skip to content
BENIBIX Learn

Stack Trace

Development🧩 Programming ConceptsErrors

Also known as Traceback, Backtrace

The crash report. It lists each function call that led to the error.

Think of it like

Think of it like footprints in snow. You follow them back to see where someone went.

Example

Emma's app crashes and prints a stack trace. Its last two lines point to line 2 of average and a ZeroDivisionError.

Why it matters

A stack trace turns "it crashed" into a file and a line number. It is the first thing to read when something breaks.

Definition

A stack trace is the report a program prints when it crashes. It lists the chain of function calls that led to the error, one per line. Each line names the file, the line number and the function. In Python the last line names the error, and the line above it is where it happened. Reading from the bottom up is the quickest way to the cause.

Example code

python
Traceback (most recent call last):
  File "st.py", line 4, in <module>
    print(average([]))
  File "st.py", line 2, in average
    return sum(scores) / len(scores)
ZeroDivisionError: division by zero
Read from the bottom. The error is last, and the line above it is where it broke.

Common mistake

Being scared off by the length. Start at the bottom; the answer is usually in the last few lines.

Key takeaways

  1. 1
    A chain of calls. Each line is one step toward the crash.
  2. 2
    File and line. It says exactly where to look.
  3. 3
    Bottom first. In Python, the cause sits at the end.

Learn it properly