Die Go -Blog -Aufhebung Panik erholen sich
func a() {
i := 0
defer fmt.Println(i)
i++
return
}
DevLorenzo
func a() {
i := 0
defer fmt.Println(i)
i++
return
}
func c() (i int) {
defer func() { i++ }()
return 1
}
mu.Lock()
defer mu.Unlock()
Calling g.
Printing in g 0
Printing in g 1
Printing in g 2
Printing in g 3
Panicking!
Defer in g 3
Defer in g 2
Defer in g 1
Defer in g 0
Recovered in f 4
Returned normally from f.
printHeader()
defer printFooter()
func b() {
for i := 0; i < 4; i++ {
defer fmt.Print(i)
}
}