June 2017
Intermediate to advanced
400 pages
10h 32m
English
Whether you use errors.New, fmt.Errorf, or a custom error, the most important thing is that you should never leave errors unhandled in your code. These different methods of defining errors give a lot of flexibility. You can, for example, put extra functions in your struct to further interrogate an error and cast the interface to your error type in the calling function to get some added functionality.
The interface itself is very simple and the only requirement is that you return a valid string. Connecting this to a struct may be useful for some high-level applications that have consistent error handling throughout but want to work nicely with other applications.
Read now
Unlock full access