Print the current stacktrace to stdout without throwing an exception

Yep, this is exactly what I was looking for!

julia> function f()
       g()
       end
f (generic function with 1 method)

julia> function g()
       h()
       end
g (generic function with 1 method)

julia> function h()
       Base.show_backtrace(stdout, backtrace())
       end
h (generic function with 1 method)

julia> f()

Stacktrace:
  [1] h()
    @ Main ./REPL[3]:2
  [2] g
    @ ./REPL[2]:2 [inlined]
  [3] f()
    @ Main ./REPL[1]:2
  [4] top-level scope
    @ REPL[4]:1
  [5] eval
    @ ./boot.jl:369 [inlined]
  [6] eval_user_input(ast::Any, backend::REPL.REPLBackend)
    @ REPL ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:139
  [7] repl_backend_loop(backend::REPL.REPLBackend)
    @ REPL ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:200
  [8] start_repl_backend(backend::REPL.REPLBackend, consumer::Any)
    @ REPL ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:185
  [9] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool)
    @ REPL ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:317
 [10] run_repl(repl::REPL.AbstractREPL, consumer::Any)
    @ REPL ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:305
 [11] (::Base.var"#891#893"{Bool, Bool, Bool})(REPL::Module)
    @ Base ./client.jl:394
 [12] #invokelatest#2
    @ ./essentials.jl:710 [inlined]
 [13] invokelatest
    @ ./essentials.jl:708 [inlined]
 [14] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
    @ Base ./client.jl:379
 [15] exec_options(opts::Base.JLOptions)
    @ Base ./client.jl:309
 [16] _start()
    @ Base ./client.jl:492
1 Like