Go · Stage 8 – Errors and Files · Lesson 46 of 64

Errors in Go

Understand errors as ordinary returned values.

Go code

number, err := strconv.Atoi("12")
fmt.Println(number, err)
Line-by-line explanation
  1. Atoi tries to convert text to int.
  2. Number receives the result.
  3. Err receives an error value.
  4. For valid text, err is nil.
Expected output
12 <nil>

Nil means no error occurred.