golang如何判断错误类型?
error类型判断的方法:
Go中返回的error类型究竟是什么呢?看源码发现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 有了一个签名为 Error() string 的方法。所有实现该接口的类型都可以当作一个错误类型。Error() 方法给出了错误的描述。
fmt.Println 在打印错误时,会在内部调用 Error() string 方法来得到该错误的描述。
以上就是golang判断错误类型的方法的详细内容,更多请关注亿速云其它相关文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。