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

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -