August 2019
Beginner to intermediate
798 pages
17h 2m
English
There are many scenarios where you might end up having to deal with a new error case while you are developing your own Go application. The error data type is here to help you to define your own errors.
This subsection will teach you how to create your own error variables. As you will see, in order to create a new error variable, you will need to call the New() function of the errors standard Go package.
The example Go code to illustrate this process can be found in newError.go and will be presented in two parts. The first part of the program is as follows:
package main import ( "errors" "fmt" ) func returnError(a, b int) error { if a == b { err := errors.New("Error in returnError() function!") return err } else { return ...Read now
Unlock full access