[英]Whats the best way to handle multiple errors in go?
Let's say I have the following function in go:假设我在 go 中有以下 function:
func SomeFunction() error {
a, err := Step1()
if err != nil {
return err
}
b, err := Step2(a)
if err != nil {
return err
}
c, err := Step3(b)
if err != nil {
return err
}
// Etc etc
return nil
}
I have to handle each error individually, and I feel like this results in very repetitive code.我必须单独处理每个错误,我觉得这会导致非常重复的代码。 I was wondering what the correct way to handle errors in a situation like this would be.
我想知道在这种情况下处理错误的正确方法是什么。
I recommend reading this blog to learn about error handling.我建议阅读此博客以了解错误处理。
https://dave.cheney.net/practical-go https://dave.cheney.net/practical-go
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.