Created
September 1, 2018 13:10
-
-
Save wcc526/ae3ede86b86d099c340002bb1ef3a9ee to your computer and use it in GitHub Desktop.
defer,panic,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
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