go - Does calling a function break recover()? -
i using library recover()s panics, , using code simplifies following:
func main() { defer rec() panic("x") } func rec() { rec2() } func rec2() { fmt.printf("recovered: %v\n", recover()) } the output of is:
recovered: <nil> panic: x ... more panic output ... notably, recover() returns nil instead of error. intended behavior?
recover must called directly deferred function.
from language spec:
the return value of recover nil if of following conditions holds:
- panic's argument nil;
- the goroutine not panicking;
- recover not called directly deferred function.
Comments
Post a Comment