Exceptions in Go?
The answer again, is simply no. From the official FAQ [1], they state that
We believe that coupling exceptions to a control structure, as in the try-catch-finally idiom, results in convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional.
Well, for people who are used to exceptions, Golang developers' decision sounds very odd. However, with the help of multi-value returns. The following example is take from the official blog [2].
f, err := os.Open("filename.ext")
if err != nil {
log.Fatal(err)
}
// do something with the open *File f
Go uses the error (it is a type) to indicate the abnormal state, which will be returned by the function.