You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Executing a call to recover inside a deferred function (but not any function called by it) stops the panicking sequence by restoring normal execution and retrieves the error value passed to the call of panic.
@seankhliao I know how to use recover. Maybe I didn't express it very clearly. In fact, I'm more wondering why it's designed this way. Since the defer function will be executed no matter what, why must it be designed to require recovery in the top-level function of defer to recover from panic? Sometimes this design makes it look more like a bug.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
version go1.16
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
recovered
What did you see instead?
panic: test
goroutine 1 [running]:
main.main()
/home/letian/work/go/src/test/test.go:11 +0x5b
exit status 2
The text was updated successfully, but these errors were encountered: