Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to catch stack overflow error in golang

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)
like image 883
zgcharley Avatar asked Aug 05 '16 22:08

zgcharley


1 Answers

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.

like image 192
JimB Avatar answered Nov 16 '22 21:11

JimB