How to ask in source for a backtrace

Is there any macro or function to get a local becktrace, i.e., the stack of calls porting the execution there at run-ime? Thanks for help.

catch_backtrace() when it’s in a catch block, otherwise there’s a function for stack traces as well which I don’t remember right now

help?> stacktrace
search: stacktrace StackTraces

  stacktrace([trace::Vector{Ptr{Cvoid}},] [c_funcs::Bool=false]) -> StackTrace

  Returns a stack trace in the form of a vector of StackFrames. (By default stacktrace doesn't return C functions, but this can be enabled.) When called
  without specifying a trace, stacktrace first calls backtrace.

julia> stacktrace()
12-element Vector{Base.StackTraces.StackFrame}:
 top-level scope at REPL[20]:1
 eval at boot.jl:368 [inlined]
 eval at Base.jl:65 [inlined]
 repleval(m::Module, code::Expr, #unused#::String) at repl.jl:222
 (::VSCodeServer.var"#107#109"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})() at repl.jl:186
 with_logstate(f::Function, logstate::Any) at logging.jl:511
 with_logger at logging.jl:623 [inlined]
 (::VSCodeServer.var"#106#108"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})() at repl.jl:187
 #invokelatest#2 at essentials.jl:729 [inlined]
 invokelatest(::Any) at essentials.jl:726
 macro expansion at eval.jl:34 [inlined]
 (::VSCodeServer.var"#61#62")() at task.jl:484
3 Likes