Created
November 25, 2018 22:38
-
-
Save cn007b/e4b3f2aa89783c24cbf68ca6ab2036df to your computer and use it in GitHub Desktop.
eop - thepkg/recover
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
// Performs recover in case of panic with error ErrorUsernameBlank | |
// otherwise panic won't be recovered and will be propagated. | |
defer recover.One(ErrorUsernameBlank, func(err interface{}) { | |
fmt.Printf("got error: %s", err) | |
}) | |
// Performs recover in case of panic with error ErrorUsernameBlank or ErrorUsernameAlreadyTaken | |
// otherwise panic won't be recovered and will be propagated. | |
defer recover.Any([]error{ErrorUsernameBlank, ErrorUsernameAlreadyTaken}, func(err interface{}) { | |
fmt.Printf("got error: %s", err) | |
}) | |
// Performs recover for all panics. | |
defer recover.All(func(err interface{}) { | |
fmt.Printf("got error: %s", err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment