Go语言基础之处理并发错误
recover goroutine中的panic 我们知道可以在代码中使用 recover 来会恢复程序中意想不到的 panic,而 panic 只会触发当前 goroutine 中的 defer 操作。 例如在下面的示例代码中,无法在 main 函数中 recover 另一个goroutine中引发的 panic。 func f1() { defer func() { if e := recover(); e != nil { fmt.Printf("recover panic:%v\n", e) } }() // 开启一个goroutine执行……