golang错误处理
1. 普通处理err != nil
1 | file, err := os.Open("example.txt") |
2. 封装泛用错误处理函数
1 | func WithErr(err error, callback func()error) error { |
3. 结构体内部保存,在结果处理
1 | type MyClass struct { |
1 | file, err := os.Open("example.txt") |
1 | func WithErr(err error, callback func()error) error { |
1 | type MyClass struct { |