# 函数

如何使用内建函数 `recover()` 终止 `panic()` 过程（参考[章节 13.3](/di-san-bu-fen-go-gao-ji-bian-cheng/13.0/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()
}
```

## 链接

* [目录](https://github.com/MartialBE/the-way-to-go_ZH_CN/blob/master/eBook/directory.md)
* 上一节：[接口](/di-si-bu-fen-shi-ji-ying-yong/18.0/18.5.md)
* 下一节：[文件](/di-si-bu-fen-shi-ji-ying-yong/18.0/18.7.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://go.xiao5.info/di-si-bu-fen-shi-ji-ying-yong/18.0/18.6.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
