// basic exception handling in Go. At the simplest you do a multiple return // where one of the returned values indicates an error. If that is non-nil, // an error occurred // // gtowell // August 2021 package main import ( "errors" "fmt" ) func main() { for i := 0; i <= 1; i++ { value, err := DoSomething(i == 1) if err != nil { fmt.Printf("%d %v\n", i, err) } else { fmt.Printf("%d %v\n", i, value) } } } // returns an error if passed parameter is true. // ths is really stupid func DoSomething(vv bool) (string, error) { if vv { return "", errors.New("some error explanation here") } else { return "Good times", nil } }