-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Description
A few corner-cases regarding panicking that I noticed in the Go spec:
1) What happens if a panic occurs while a goroutine is already panicking?
Gc/gccgo seem to allow recursive panicking and recovering: http://play.golang.org/p/tBkwgyzmuT
But if a deferred function panics without any recovery, then the original panic is lost: http://play.golang.org/p/KqwGiWGMAx
2) The Go spec says "The return value of recover is nil if any of the following conditions holds: [...] recover was not called directly by a deferred function."
Gc/gccgo though seem to also have recover return nil in deferred functions if they were executed because of normal (i.e., non-panicking) function return: http://play.golang.org/p/a-fl_9Gga0
3) The Go spec says "Suppose a function G defers a function D that calls recover and a panic occurs in a function on the same goroutine in which G is executing. [...] If D returns normally, without starting a new panic, the panicking sequence stops."
Nit: I think the intention here is understood, but the wording could probably be improved somewhat. As quoted in item 2 above, the spec later explicitly refers to deferred functions that "directly" call recover. Omitting "directly" here suggests that indirect calls to recover should still stop the panicking sequence, but they'll return nil instead of the panic value.