Created
June 25, 2022 15:59
-
-
Save GhazeyAhmed/ca4589a9db5bd47b53f02d93a6fe0a65 to your computer and use it in GitHub Desktop.
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
import "fmt" | |
func main() { | |
freakOut() | |
fmt.Println("Exiting normally") | |
} | |
func freakOut() { | |
defer calmDown() | |
panic("Oh no") | |
fmt.Println("I won't run :(") | |
} | |
func calmDown() { | |
recover() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment