Print current stacktrace

Is there a function ready to use that prints to stdout/stderr the current stacktrace from the point it is invoked ?

1 Like

Does println(stacktrace()) do what you want?


I sometimes use:

foreach(((ii,frame),)->println("[$ii] $frame"), enumerate(stacktrace()))

Which gives:

julia> foreach(((ii,frame),)->println("[$ii] $frame"), enumerate(stacktrace()))
[1] top-level scope at REPL[15]:1
[2] eval at boot.jl:373 [inlined]
[3] eval_user_input(ast::Any, backend::REPL.REPLBackend) at REPL.jl:150
[4] repl_backend_loop(backend::REPL.REPLBackend) at REPL.jl:241
[5] start_repl_backend(backend::REPL.REPLBackend, consumer::Any) at REPL.jl:226
[6] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool) at REPL.jl:359
[7] run_repl(repl::REPL.AbstractREPL, consumer::Any) at REPL.jl:346
[8] (::Base.var"#919#921"{Bool, Bool, Bool})(REPL::Module) at client.jl:394
[9] #invokelatest#2 at essentials.jl:716 [inlined]
[10] invokelatest at essentials.jl:714 [inlined]
[11] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool) at client.jl:379
[12] exec_options(opts::Base.JLOptions) at client.jl:309
[13] _start() at client.jl:495

the numbers are nice for readabilty.