Go expresses error state with error values. There’s no try-except or try-catch blocks.

Functions often return error value (by convention should be always last), and it’s a responsibility of the calling code to handle errors. Example:

i, err := strconv.Atoi("42")
if err != nil {
    fmt.Printf("couldn't convert number: %v\n", err)
    return
}
fmt.Println("Converted integer:", i)

error package is used to handle errors in Go.

Built-in error type is used for errors.

type error interface {
	Error() string
}

The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error.

References