How to determine error type in golang

Release: 2020-01-14 15:24:17
Original
5233 people have browsed it

How to determine error type in golang

How to determine error type:

What is the error type returned in Go? Looking at the source code, we found that the error type is a very simple interface type, as follows

// 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 }
Copy after login

error has a method signed Error() string. All types that implement this interface can be treated as an error type. The Error() method gives a description of the error.
fmt.Println will call the Error() string method internally when printing an error to get a description of the error.

For more golang knowledge, please pay attention to thegolang tutorialcolumn.

The above is the detailed content of How to determine error type in golang. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!