6. Errors
Activity 6.01: Creating a Custom Error Message for a Banking Application
Solution:
- Create a directory called Activity6.01 inside your
$GOPATH. - Save a file inside of the directory created in step 1 called
main.go. - Define
package mainand import two packages,errorsandfmt:package main import (   «errors»   «fmt» )
- Next, define our custom error that will return an error that displays
"invalid last name":var ErrInvalidLastName = errors.New("invalid last name") - We need one more custom error that will return an error that displays
"invalid routing number":var ErrInvalidRoutingNum = errors.New("invalid routing number") - In the
main()function, we will print each of the errors:func main() { Â Â fmt.Println(ErrInvalidLastName) Â Â fmt.Println(ErrInvalidRoutingNum) } - At the command line, navigate to the directory created in step 1.
- At the command line...