Handling errors and the Error interface

The Error interface is a pretty small and simple interface:

type Error interface{
Error() string
}

This interface is elegant because it's simple to make anything in order to satisfy it. Unfortunately, this also creates confusion for packages that need to take certain actions depending on the error received.

There are a number of ways to create errors in Go; this recipe will explore the creation of basic errors, errors that have assigned values or types, and a custom error using a structure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.63.90