The returned error-value is can be nil, meaning success, and non-nil, meaning failure.

We can make functions return errors:

func divide(num int) (int, error) {
	if num != 0 {
		return num / 2, nil
	}
 
	return 0, fmt.Errorf("Can't divide 0")
}
 
func main() {
	var result, err = divide(0)
 
	if err == nil {
		fmt.Println("Success: ", result)
	} else {
		fmt.Println("Failure: ", err)
	}
 
}

Next chapter: Concurrency