Skip to content

Instantly share code, notes, and snippets.

@wcc526
Created September 1, 2018 13:10
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 wcc526/ae3ede86b86d099c340002bb1ef3a9ee to your computer and use it in GitHub Desktop.
Save wcc526/ae3ede86b86d099c340002bb1ef3a9ee to your computer and use it in GitHub Desktop.
defer,panic,recover
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
testpanics()
fmt.Println("World")
}
func testpanics() {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
fmt.Println("We recover from panic")
}
}()
panic("A panic happend")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment