Is there any way to catch stack overflow error in golang? Currently I'm using go recover() do this job(below code snippet), looks like stack overflow error can't be caught.
defer func() {
if x := recover(); x != nil {
log.Error("In recover, cought error====================", x)
}
}()
fn(xxx)
What you see in the output is a "fatal error", not a panic.
fatal error: stack overflow
You can only use recover()
to recover from panics. A stack overflow is a fatal error thrown by the runtime which causes the process to print a stack trace and exit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With