Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created September 12, 2016 04:06
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 bradclawsie/394e0c1ccf0d813e029b5125f65bca1a to your computer and use it in GitHub Desktop.
Save bradclawsie/394e0c1ccf0d813e029b5125f65bca1a to your computer and use it in GitHub Desktop.
panic.go
package main
import (
"errors"
"log"
)
func final() {
log.Printf("cleaning up")
if c := recover(); c != nil {
if err,ok := c.(error); ok {
// Do something useful...then:
log.Fatal(err.Error())
} else {
log.Printf("unexpected panic")
panic(c)
}
}
}
func main() {
log.Printf("hello")
defer final()
log.Printf("goodbye")
panic(errors.New("oh dear!"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment