Files
the-way-to-go_ZH_CN/eBook/18.6.md
Haigang Zhou fa1cfcc67f 第十七十八章 (#833)
Co-authored-by: Joe Chen <jc@unknwon.io>
2022-05-19 19:57:23 +08:00

24 lines
521 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 18.6 函数
如何使用内建函数 `recover()` 终止 `panic()` 过程(参考[章节 13.3](13.3.md)
```go
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()
}
```
## 链接
- [目录](directory.md)
- 上一节:[接口](18.5.md)
- 下一节:[文件](18.7.md)