github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/recover5b.gno (about) 1 package main 2 3 func main() { 4 f() 5 } 6 7 func f() { 8 defer func() { println("f recover", recover()) }() 9 defer g() 10 panic("wtf") 11 } 12 13 func g() { 14 defer func() { 15 // g() shouldn't be able to recover from f()'s panic, because the recover 16 // is declared in a deferred closure that is absent from the stack at the 17 // time of the panic. 18 // See go behavior here https://go.dev/play/p/CcMGgY606O- 19 // See Rob's examples https://groups.google.com/g/golang-nuts/c/HOXNBQu5c-Q/m/Je0qo1hbxIsJ 20 println("g recover", recover()) 21 }() 22 } 23 24 // Output: 25 // g recover undefined 26 // f recover wtf