Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #253 Print stack trace

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

import Carp 'cluck';
cluck 'print this message and a full stack track';
import "runtime/debug"
debug.PrintStack()
import GHC.Stack
msgStacktraced :: HasCallStack => String -> IO ()
msgStacktraced msg = putStrLn (msg ++ "\n" ++ prettyCallStack callStack)
console.trace()
import static java.lang.System.out;
import static java.lang.Thread.currentThread;
for (var e : currentThread().getStackTrace())
    out.println(e);
dump_stack(stdout,0);
import inspect
for frame in inspect.stack():
    print(frame)
puts caller
use backtrace::Backtrace;
let bt = Backtrace::new();
println!("{:?}", bt);

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