Errors
Go handles errors with values, not exceptions. The built-in error interface looks like this:
type error interface {
Error() string
}
Any type with an Error() string method satisfies it — the same implicit satisfaction you’ve seen throughout this chapter.
Functions typically return an error as their last value. Callers check it:
i, err := strconv.Atoi("42")
if err != nil {
fmt.Printf("couldn't convert number: %v\n", err)
return
}
fmt.Println("Converted integer:", i)
nil means success. Non-nil means something went wrong.