Logo

Programming-Idioms

  • Python
  • Java

Idiom #253 Print stack trace

Print the stack frames of the current execution thread of the program.

import static java.lang.System.out;
import static java.lang.Thread.currentThread;
for (var e : currentThread().getStackTrace())
    out.println(e);
import inspect
for frame in inspect.stack():
    print(frame)
import "runtime/debug"
debug.PrintStack()

Prints to standard error

New implementation...
< >
programming-idioms.org