错误

Errors 错误

原文:https://go.dev/ref/spec#Errors

预先声明的error类型被定义为

1
2
3
type error interface {
	Error() string
}

​ 它是代表错误条件的常规接口,nil值代表没有错误。例如,可以定义一个从文件中读取数据的函数:

1
func Read(f *File, b []byte) (n int, err error)