Created
October 10, 2019 16:08
-
-
Save kardolus/77961504240e5e67dfb554b14a810b83 to your computer and use it in GitHub Desktop.
Common error handling pattern
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
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func main() { | |
exit(run()) | |
} | |
func exit(err error) { | |
if err == nil { | |
os.Exit(0) | |
} | |
fmt.Printf("%s", err) | |
os.Exit(1) | |
} | |
func run() error { | |
fmt.Println("Hello world") | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment