Skip to content

Instantly share code, notes, and snippets.

@petergtz
Last active August 2, 2017 22:02
Show Gist options
  • Save petergtz/8dc38c407ace9a1c4af6a369e13ea590 to your computer and use it in GitHub Desktop.
Save petergtz/8dc38c407ace9a1c4af6a369e13ea590 to your computer and use it in GitHub Desktop.
A simple example of a new error handling concept in Go
func Caller(arg int) {
result := SomeFunction(arg) on_error e {
fmt.Printf("Wrong input: %v", e)
return
}
fmt.Printf("Result: %v", result)
}
func SomeFunction(arg int) int fails_with error {
if arg == 42 {
fail errors.New("Can't work with 42")
}
return arg + 3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment