dreamwind1985 2016-08-05 22:00
浏览 503
已采纳

如何在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)
  • 写回答

3条回答 默认 最新

  • dshmvqnl98119 2016-08-05 22:16
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?