New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtin: recover returns nil in an anonymous function from an variable #56254
Comments
Use the code to fix it. |
This fixes your issue without modifying the code too much
|
I needs to commit or rollback of a transaction and return err if it happens. That is why I needs to func(){}() in defer. |
I think I misunderstands recover because my case differs from docs explanation, isn't it? Docs says:
|
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I creates and puts an anonymous function in a variable. Then, I uses the variable in defer function to recover panic.
https://go.dev/play/p/w5yIvY-q5BL
What did you expect to see?
Recovery returns a message from the panic.
What did you see instead?
Recovery returns nil and program shutdown with the panic.
The text was updated successfully, but these errors were encountered: