Skip to content

Instantly share code, notes, and snippets.

@mlowicki
Last active October 13, 2016 06:08
Show Gist options
  • Save mlowicki/a4b08c17d5e992d76d6f66f9c6f90d77 to your computer and use it in GitHub Desktop.
Save mlowicki/a4b08c17d5e992d76d6f66f9c6f90d77 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func f() {
fmt.Println("Start f")
defer func() {
fmt.Println("Deferred in f")
}()
g()
fmt.Println("End f")
}
func g() {
fmt.Println("Start g")
defer func() {
fmt.Println("Deferred in g")
}()
h()
fmt.Println("End g")
}
func h() {
fmt.Println("Start h")
defer func() {
fmt.Println("1st deferred in h")
}()
defer func() {
fmt.Println("2nd deferred in h")
if p := recover(); p != nil {
fmt.Printf("Panic found: %v\n", p)
}
}()
defer func() {
fmt.Println("3rd deferred in h")
}()
panic("boom!")
}
func main() {
f()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment