Recover is a built-in function that regains control of a panicking goroutine. Recover is only useful inside deferred functions. During normal execution, a call to recover will return nil and have no other effect. If the current goroutine is panicking, a call to recover will capture the value given to panic and resume normal execution.
I think I didn't break any rules.--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Ok40EBXxQ2Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXUWYdq%3DzSSw4V_HvNzrNpnrt1awEZbRFca0f6qHoBdsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sorry for the bad formatting.> recover must be called directly by a deferred functionfunc logPanic() {
defer func() {
if err := recover(); err != nil {
fmt.Println("got panic")
return
}
}()
}This still not working.Recover is a built-in function that regains control of a panicking goroutine. Recover is only useful inside deferred functions. During normal execution, a call to recover will return nil and have no other effect. If the current goroutine is panicking, a call to recover will capture the value given to panic and resume normal execution.
I think I didn't break any rules.
Ian Lance Taylor <ia...@golang.org> 于2019年7月17日周三 下午9:59写道:
On Wed, Jul 17, 2019 at 5:11 AM Tamás Gulácsi <tgula...@gmail.com> wrote:
>
> The "recover()" call must be in the deferred part.
Yes, as the spec says, recover must be called directly by a deferred function.
When sending code to this list, please use a link to the Go playground
or use plain text. The highlighted text with a black background is
unreadable. Thanks.
Ian
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Ok40EBXxQ2Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXUWYdq%3DzSSw4V_HvNzrNpnrt1awEZbRFca0f6qHoBdsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
----刘志平