Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GhazeyAhmed
Created June 25, 2022 17:43
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 GhazeyAhmed/fbe737e66ec4f9b5401e4b3b8ceed4af to your computer and use it in GitHub Desktop.
Save GhazeyAhmed/fbe737e66ec4f9b5401e4b3b8ceed4af to your computer and use it in GitHub Desktop.
recover-return-value
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