Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Stack trace

Стектрейс

A snapshot of the function calls active at a particular moment in a program. When an error occurs, it helps you locate the failing line and see which calls led to it.

Also known as: трейсбек, traceback

What a stack trace shows

A stack trace answers “How did the program get to this line?” Suppose a checkout handler calls load_cart(), which calls parse_quantity(). While parse_quantity() runs, the other two calls are still waiting for it to return, so all three can appear in the trace. A function that finished before parse_quantity() was called won't be there. A stack trace is a snapshot, not a history of everything the program did.

From call stack to stack trace

Each active function or method call has a stack frame. A call adds a frame; returning removes it. The same function can appear in multiple frames when it calls itself recursively. A formatted trace typically identifies each function and, when source locations are available, its file and line number. The exception type and message are often printed alongside the frames, but they tell you what failed rather than how execution reached it.

Languages and tools format traces differently. Python's exception output, called a traceback, normally lists the outermost call first and ends with the exception type and message. A Java exception normally prints its type and message first, followed by frames starting nearest the point of failure. Don't assume that the first frame is always the one to investigate.

Example: a failing checkout

Traceback (most recent call last):
  File "checkout.py", line 21, in checkout
    load_cart(payload)
  File "checkout.py", line 12, in load_cart
    parse_quantity(item["quantity"])
  File "checkout.py", line 6, in parse_quantity
    return int(raw)
ValueError: invalid literal for int() with base 10: 'two'

The message tells you that int() couldn't parse the string 'two'. The closest frame points to line 6, where the conversion failed. The caller on line 12 shows which field supplied the value. To decide what to fix, check the input contract: should quantity be a number, or is the program expected to accept words? The trace pinpoints the failed operation, but it doesn't settle that question.

Using traces in practice

You'll see stack traces in failing test output, production error logs, and debuggers. You don't need an exception to inspect the stack: pause at a breakpoint and select a frame to see its location and, where available, its local variables. In a long error log, find the frame in your code nearest the failure and check what it passed to any library involved. If one exception wraps another, read the underlying exception as well; the outer message may only say which operation failed.

An ordinary stack trace may not show who scheduled an asynchronous task. The scheduling call might already have returned when the task runs. Some runtimes and debuggers add async context to bridge that gap. A stack trace is also different from a distributed trace, which follows a request across services rather than showing function calls within one program.

In an interview

If you're handed an unfamiliar trace, name the exception, identify the failing line, and explain what you'd check next. Distinguish what the trace proves from what you suspect: a conversion failure is visible in the trace; whether the caller sent bad input or the parser misunderstood valid input is something you'd verify.