On Fri, May 27, 2022 at 10:42 AM Aggarwal Sre <
sre.ag...@gmail.com> wrote:
>
> Is there a recommended pattern besides adding a defer call ( with recover call, to collect debug stack trace) to each goroutine, for collecting a stack trace when a golang is crashing due to any sort of panic.
>
> In other words, is there a way to register an uber handler ( probably using OS signals) at the main function level, to indicate that a golang program crashed and stacktrace to clearly specify where exactly?
A panic handle is run at the bottom of the stack. If you write this:
defer func() {
if recover() != nil {
fmt.Printf("%s", debug.Stack())
}
}()
in your main function, it will print a stack trace showing the point
of the panic.
Ian