ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 18.6 函数 如何使用内建函数`recover`终止`panic`过程(参考[章节13.3](https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/13.3.md)): ``` 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() } ```