2 ms·
Go errors are routinely ignored. Even Hello World ignores the error return. https://gobyexample.com/hello-world https://gobyexample.com/hello-world
by millstone 9y ago
Go errors are routinely ignored. Even Hello World ignores the error return.
https://gobyexample.com/hello-world https://gobyexample.com/hello-world
- thewhitetulip 9y agoNo. That is incorrect. Errors are to be handled by the programmer and every book I read says "We are ignoring errors here for the sake of simplicity, you are strongly advised not to ignore them". I have said so in the intro textbook I wrote.
- junke 9y agoError 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