Skip to content

Instantly share code, notes, and snippets.

@cn007b
Created November 25, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cn007b/e4b3f2aa89783c24cbf68ca6ab2036df to your computer and use it in GitHub Desktop.
Save cn007b/e4b3f2aa89783c24cbf68ca6ab2036df to your computer and use it in GitHub Desktop.
eop - thepkg/recover
// 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