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

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

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

asp.net mvc - breakpoint on javascript in CSHTML? -