如何使用内建函数recover终止panic过程(参考章节13.3):
recover
panic
func protect(g func()) { defer func() { log.Println("done") // Println executes normally even if there is a panic if x := recover(); x != nil { log.Printf("run time panic: %v", x) } }() log.Println("start") g() }
目录
上一节:接口
下一节:文件
Last updated 6 years ago