Skip to content

Instantly share code, notes, and snippets.

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