Created
June 25, 2022 17:49
-
-
Save GhazeyAhmed/6d7d44c642ed12444b7c76aa5ff9ff3a to your computer and use it in GitHub Desktop.
recover-return
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() { | |
s := foo() | |
fmt.Printf("main received: %q\n", s) | |
} | |
func foo() (s string) { | |
defer func() { | |
if err := recover(); err != nil { | |
fmt.Printf("recovering from: %q\n", err) | |
s += " during" | |
} | |
}() | |
s = "before" | |
panic("disaster") | |
s += " after" | |
return s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment