liveBook · Manning

Stack trace

As explained in The Art of Code

A stack dump is a diagnostic snapshot showing the call stacks of threads or goroutines in a running or failed process.

A stack trace is a snapshot of the current method call stack at a point in execution. It records the sequence of calls that led there, commonly including class and method names, file names, and line numbers. Although often produced when an exception is thrown, it can also be generated deliberately for logging, profiling, or debugging. section 7.1.1

Treat a stack trace as developer-facing diagnostic evidence, not as a user-facing error message. A raw trace can overwhelm users and may reveal filesystem paths, internal hostnames, SQL queries, or other sensitive implementation details. Failure handling should translate the failure into an understandable response while retaining useful diagnostic information for investigation. section 7.1.1

Use a stack trace according to the failure context:

  • Follow its call sequence to locate the code path and exact line implicated by a reproducible failure. section 10.3.2
  • Combine it with timestamps, logs, network traces, metrics, and other evidence when reconstructing an intermittent or unreproducible failure. section 10.3.2
  • Escalate beyond it when a fatal runtime failure leaves too little information or the process cannot support normal debugging. section 7.1.4

Tracing an HTTP 500

Reproduce a broken web form, inspect the browser console and network trace, then correlate the HTTP 500 timestamp with backend logs. A stack trace in those logs can pinpoint the faulty line of code, narrowing the investigation from a user-visible symptom to a concrete defect. section 10.3.2

For severe failures, a stack trace may be only one clue. JVM diagnostics can add heap dumps, garbage-collection logs, fatal crash reports, and live runtime data; C and C++ use core dumps and GDB; Rust can emit enabled panic backtraces; Go prints a trace for an unrecovered panic and can create stack dumps. Fatal failures generally call for code or infrastructure correction, or fail-fast behavior, rather than in-process recovery. section 7.1.4

Table 7.1 Summary of failure types and handling strategies
Type of failure
Description
Business logic errors
Violations of business rules or expected usage constraints that the system must anticipate and communicate clearly
Technical problems
Failures caused by external systems, infrastructure, configuration, or unavailable technical dependencies
Programming errors
Defects in the code itself caused by incorrect logic, invalid assumptions, or broken invariants
Fatal errors
Critical runtime failures that compromise process stability and usually prevent normal recovery

Compare fatal errors with business logic errors, technical problems, and programming errors before choosing a response; a trace helps investigate, but does not determine the failure category. section 7.1.4

How The Art of Code covers it

How deep it goes
Defines call-stack contents and uses, then shows trace-led investigation and limits during fatal failures.
Examples
Follows an HTTP 500 from browser network traces to backend logs and a faulty code line.
What you can do after
Diagnose/debug with stack traces by correlating call paths with logs, timestamps, and surrounding diagnostic evidence.
How it connects
Connects stack traces to exceptions, logging, profiling, debugging, heap dumps, core dumps, and failure handling.

Also explained in

Compare how 7 books explain stack trace →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.