相关疑难解决方法(0)

去:从延迟回来

如果它发生混乱(在Go中)我想从函数返回错误:

func getReport(filename string) (rep report, err error) {
    rep.data = make(map[string]float64)

    defer func() {
        if r := recover(); r != nil {
            fmt.Println("Recovered in f", r)
            err, _ = r.(error)
            return nil, err
        }
    }()
    panic("Report format not recognized.")
    // rest of the getReport function, which can try to out-of-bound-access a slice
    ...
} 
Run Code Online (Sandbox Code Playgroud)

我似乎误解了恐慌和推迟的概念.任何人都可以开导我吗?

return go panic

42
推荐指数
3
解决办法
2万
查看次数

标签 统计

go ×1

panic ×1

return ×1