mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 17:36:12 +08:00
modified: 18.1.md
new file: 18.10.md new file: 18.11.md new file: 18.2.md new file: 18.3.md new file: 18.4.md modified: 18.5.md new file: 18.6.md new file: 18.7.md new file: 18.8.md new file: 18.9.md modified: directory.md
This commit is contained in:
23
eBook/18.6.md
Normal file
23
eBook/18.6.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 18.6 函数
|
||||
|
||||
如何使用内建函数recover停止panic过程(参考13.3小节):
|
||||
|
||||
```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)
|
||||
- 上一章:[运算符模板和接口](17.4.md)
|
||||
- 下一节:[字符串](18.1.md)
|
||||
Reference in New Issue
Block a user