News for hackers. Stuff that matters.
Re:Golang landmines by Animats on Sunday September 18, 2016 @02:13AM (#12524168)
What can you do if you detect an error in a "defer" clause? Besides panic?
Re:Golang landmines by amscanne on Sunday September 18, 2016 @03:58AM (#12524366)
With named return values, the defer can modify them. For example:

func Foo() (err error) { defer func() { err = errors.New("some error") }() }

The function will return the "some error" error.

Re:Golang landmines by ansible on Sunday September 18, 2016 @02:54AM (#12524251)
Well, I don't know if panic is the right option.

However, checking the return value is always a good idea, and any errors should at least be logged.

I too wish it was less cumbersome to use defer properly.

Re:Golang landmines by giovannibajo1 on Sunday September 18, 2016 @03:07AM (#12524285)
One thing you can do is simply use BOTH a defer Close and a straight-path Close with error-checking.