by germainelong · 7y ago · 0 comments
In particular Go (like C) has no built-in exception "throwing" / unwinding support, so for any function call where you want to pass an error onto the caller, you need to do something like
result, err := try_to_get_a_result()
if err != nil {
return nil, err
}
See also https://blog.golang.org/error-handling-and-go . As far as I can tell, all of the if-statements without else-clauses are doing just this.(It would be nice in theory if there were better language support for making this lexically obvious but they're in a language where that's not doable.)
For instance, this would not be a simple error check:
server, err := find_current_server()
if server != nil {
...
}
because if find_current_server() believes that it's a non-exceptional case that there might be no server at all (i.e., it might return nil, nil instead of nil and an error), then you absolutely want to handle that case.