-
Notifications
You must be signed in to change notification settings - Fork 570
Open
Description
Consider the following code:
package main
import "fmt"
func main() {
defer func() { fmt.Println(recover()) }()
defer func() { fmt.Println(recover()) }()
defer panic(2)
panic(1)
}When executed by go:
$ go run main3.go
2
<nil>When executed by GopherJS:
$ gopherjs run main3.go
2
1Note that in the upstream implementation the later panic overrides the earlier panic, and only one call to recover() is necessary. However, GopherJS requires a separate call to recover from each panic. While go spec isn't explicit about it, it doesn't say that there is some kind of stack of panics. Instead it only defines two states or "panicing" and "not panicing" and a successful recover() call clears the state of panicing and resumes normal execution.