Before learning the Go language, I believed that Python was the most convenient language for providing error and exception handling for programmers; after learning the Go language, my opinion has not changed at all…
@DGideas
This article references @ethancai’s article and @davecheney‘s keynote speech at Gocon Spring 2016, as well as several blog posts and documents on golang.org.
The Go language offers a unique error handling experience compared to other programming languages. One of the distinctive features of the Go programming language is the frequent occurrence of the if err != nil
statement block. Thanks to the multiple return values feature of Go functions, a function that may not always execute successfully can use an error type return value to indicate whether its execution process is in an abnormal state, for example:
f, err := os.Open("filename.ext")
if err != nil {
log.Fatal(err)
}