Isn't the code should be: *func CopyFile() {* * ...* * if err != nil {* * return* * }*
* defer func() { err = src.Close() }()* * ...* *}* On Thursday, November 25, 2021 at 12:18:20 PM UTC+8 Ian Lance Taylor wrote: > On Wed, Nov 24, 2021 at 6:14 PM Fannie Zhang <fannie...@arm.com> wrote: > > > > There is some incorrect code in > https://go.dev/blog/defer-panic-and-recover blog. > > > > The original code is > > func CopyFile() { > > ... > > if err != nil { > > return > > } > > defer src.Close() > > ... > > } > > > > I think the correct code should be > > func CopyFile() { > > ... > > defer src.Close() > > if err != nil { > > return > > } > > ... > > } > > > > I do not know how to modify the go blog, can anyone help? Thank you. > > If you want to update the blog, send a patch for > golang.org/x/website/_content/blog. > > (But please don't send this particular change. As Kurtis noted, the > existing code is correct, and your change would not be correct. > Thanks.) > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e1da6a65-67e6-4ae3-943b-4f1124cafa20n%40googlegroups.com.