Last active
August 2, 2017 22:02
-
-
Save petergtz/8dc38c407ace9a1c4af6a369e13ea590 to your computer and use it in GitHub Desktop.
A simple example of a new error handling concept in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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