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.Dismiss alert
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Screenshot
What did you do?
I was reading this great blog post, and it proposed that using "defer" in this situation would solve the problem of unclosed files. However, in the code snippet provided in the blog, this problem prevails as the defer statement came after the error handling. I was curious that maybe I'm wrong so I wrote a little dummy code to test if the defer would be effective even if it's located after a return statement. Turns out that it will not work as the blog post assumed.
It did not print out the "deferred end", but when I place the defer before the if block, it works as expected. So I thought I report this minor issue so that new comers like me would not get a wrong idea from the blog post.
The text was updated successfully, but these errors were encountered:
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.
What is the URL of the page with the issue?
Defer, Panic, and Recover
What is your user agent?
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Screenshot
What did you do?
I was reading this great blog post, and it proposed that using "defer" in this situation would solve the problem of unclosed files. However, in the code snippet provided in the blog, this problem prevails as the defer statement came after the error handling. I was curious that maybe I'm wrong so I wrote a little dummy code to test if the defer would be effective even if it's located after a return statement. Turns out that it will not work as the blog post assumed.
The output of this code when I run it is:
into if
It did not print out the "deferred end", but when I place the defer before the if block, it works as expected. So I thought I report this minor issue so that new comers like me would not get a wrong idea from the blog post.
The text was updated successfully, but these errors were encountered: