Show the full error stacktrace in REPL and pipe it to a file?

Once an error occurs and the REPL shows the error and the stacktrace, is there a good way to record it and pipe/record it to a file just from the REPL?

julia> myFunction()
ERROR: Error in module.
Stacktrace:
 [1] myModuleFunction() at /myModule.jl:6
 [2] myOtherFunction() at /main.jl:10
 [3] myFunction() at /main.jl:6
 [4] top-level scope at REPL[2]:1

julia> [Maybe a command here to pipe the above stacktrace to a file?]

One of my main issues that prevent me from just copy and pasting is that sometimes I get errors that consume the whole REPL and I can’t even scroll up anymore. Sometimes this even happens when I have the REPL fullscreen in a terminal window.

Other times it’d just be nice have a REPL feature that allows this to be done. So I was wondering if anyone had any ideas.

Going over the Julia docs, I found the StackTraces module, but when I call stacktrace(catch_backtrace()) in the REPL after the the error occured, it just gives me something empty. I can try wrapping my function in a try-catch block after-the-fact and rerunning it but I might get the error after a long time and don’t want to rerun the function I just ran.

2 Likes