4 ms·
Error handling is what happen after you discover there was an error. In Go, "checking" for errors may be skipped (and people make mistake, even True Programmers
by junke 9y ago
Error handling is what happen after you discover there was an error.
In Go, "checking" for errors may be skipped (and people make mistake, even True Programmers), in which case they are handled just as if they were ignored.
Even if the error can be ignored for fmt.Println, it is not clear from the example whether it was even taken into account or not. The following could be required:
_ := fmt.Println("hello world")
That means that the function call can return an error, and thus you have to use the return value, but the programmer decided to ignore it. Contrast it with:
fmt.Println("hello world")
Did the programmer know there was possibly an error? What happens if there is an error (not specifically for this example, but in general), and you don't check for it? then it is ignored.
In another language, the same line could be the source of an error; but only error handling depends on the programmer, not error checking. Moreover, the default handling strategy is to abort execution. Actually ignoring errors requires more work.
And errcheck is apparently no silver bullet: https://github.com/golang/go/issues/20148 https://github.com/golang/go/issues/20148