3 ms·
> it's too easy to forget an error check. How? What exactly makes this "too easy"? In regards to a functions error returns, there are exactly two things a cal
by usrbinbash 3y ago
> it's too easy to forget an error check.
How? What exactly makes this "too easy"?
In regards to a functions error returns, there are exactly two things a caller can do
func foo() (int, error) {
// foo code
}
// explicitely ignore the error
foo()
val, _ := foo()
// handling the error
val, err := foo()
_, err := foo()
If I do the latter, I cannot ignore `err`. If I do, the compiler yells at me because there is now an unused value in my code.
If I do the former, then I made the conscious choice that the error doesn't matter to me. Yes, this goes for `foo()` as well, because Go makes it exceedingly clear that errors are just return values, and that call ignores all returns.
- VBprogrammer 3y agoUnless things have changed, if the return is only a single error value then it's possible to overlook capturing it.