As we all know, panics produce a stacktrace to stdout (Playground link).:
panic: runtime error: index out of range
goroutine 1 [running]:
main.main()
/tmp/sandbox579134920/main.go:9 +0x20
And it seems when you recover from a panic, recover()
returns only an error
which describes what caused the panic (Playground link).
runtime error: index out of range
My question is, is it possible to store the stacktrace which is written to stdout? This provides much better debugging information than the string runtime error: index out of range
because it shows the exact line in a file which caused the panic.