【Golang 标准库】package errors
Part1
builtin/builtin.go:260
Go 中的 error 类型就是一个普通的接口,普通的值。error 类型的定义位于 package builtin 中。
1 | // The error built-in interface type is the conventional interface for |
Part2
errors/errors.go
1 | package errors |
我们经常使用 errors.New() 来返回一个 error 对象。其实,errors.New() 返回的是内部 errorString 对象的指针。之所以返回指针,是为了防止两个 error 比较时产生意料之外的相等情况。
Part3
fmt/errors.go
fmt.Errorf 可以基于格式化字符串来生成 error 对象,函数内部实际调用了errors.New(s)方法。
1 | // Errorf formats according to a format specifier and returns the string as a |
Part4
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Robby!
评论

