Last active
October 17, 2018 17:47
-
-
Save tylerdmace/dee31310d6815dedd93c72c64eb32c97 to your computer and use it in GitHub Desktop.
Error nilification 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
package main | |
import ( | |
"errors" | |
"fmt" | |
) | |
func main() { | |
err := test() | |
if err != nil { | |
err = nil // Nilify error | |
if err != nil { // For critical code, you should nilify this error too | |
fmt.Println("You done fucked up. -- Stomach after Chipotle") | |
} | |
fmt.Println("Everything is hunky dory. -- David Bowie") | |
} | |
} | |
func test() error { | |
return errors.New("error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment