Created
June 25, 2022 17:43
-
-
Save GhazeyAhmed/fbe737e66ec4f9b5401e4b3b8ceed4af to your computer and use it in GitHub Desktop.
recover-return-value
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() string { | |
defer func() { | |
if err := recover(); err != nil { | |
fmt.Printf("recovering from: %q\n", err) | |
} | |
}() | |
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