1. 18.6 函数

如何使用内建函数recover终止panic过程(参考章节13.3):

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()
}

1.1. 链接

Copyright © studygolang.com 2013 all right reserved,powered by Gitbook该文件修订时间: 2017-07-21 20:23:41

results matching ""

    No results matching ""