Go doesn’t throw errors like JavaScript, but it returns them. While writing a function, you should return the value and an error as a second value so that developer can check condition of the returned value.
func sendSMSToCouple(msgToCustomer, msgToSpouse string) (float64, error) {
cCost, err := sendSMS(msgToCustomer)
if err != nil {
return cCost, err
}
sCost, err := sendSMS((msgToSpouse))
if err != nil {
return sCost, err
}
combinedCost := cCost + sCost
return combinedCost, nil
} Go also has errors package that allows you to create an error
func divide(a, b int) (int, error) {
if b == 0 {
return 0, errors.New("Don't divide by 0!")
}
return a/b, nil
}