Proposal: A built-in Go error check function, try
The ideas discussed in the draft design centered around a new unary operator which simplified explicit checking of an error value returned by some expression (typically a function call), a declaration for error handlers, and a set of rules connecting the two new language constructs. Invoking with a function call as in (pseudo-code)
turns into the following (in-lined) code:
In other words, if the last argument supplied to , of type , is not nil, the enclosing function’s error result variable (called in the pseudo-code above, but it may have any other name or be unnamed) is set to that non-nil error value before the enclosing function returns. If returns a non-nil error, is expected to return from the enclosing function, but there isn’t any such (Go) function (nor a last result parameter of type ) since we are running in a separate goroutine.
Source: github.com