目录 error 的困局 尝试破局 Errors are just values handle not just check errors Only handle errors once 小结 胎死腹中的 try 提案 go 1.13 的改进 fmt.Errorf Unwrap Is As 总结 参考资料 写过 C 的同学知道,C 语言中常常返回整数错误码(errno)来表示函数处理出错,通常用 -1 来表示错误,用 0 表示正确. 而在 Go 中,我们使用 error 类型来表示错误,不过它不…
error定义 数据结构 go语言error是一普通的值,实现方式为简单一个接口. // The error built-in interface type is the conventional interface for // representing an error condition, with the nil value representing no error. type error interface { Error() string } 创建error 使用errors.Ne…