Panic Stack
What will be printed when the code below is executed?
package main
func f1() {
defer println("f1-begin")
f2()
defer println("f1-end")
}
func f2() {
defer println("f2-begin")
f3()
defer println("f2-end")
}
func f3() {
defer println("f3-begin")
panic(0)
defer println("f3-end")
}
func main() {
f1()
}
Answer
f3-begin
f2-begin
f1-begin
panic: 0
goroutine 1 [running]:
main.f3()
/tmp/sandbox423933384/main.go:17 +0x80
main.f2()
/tmp/sandbox423933384/main.go:11 +0x80
main.f1()
/tmp/sandbox423933384/main.go:5 +0x80
main.main()
/tmp/sandbox423933384/main.go:22 +0x20