x, y, z, err := someFunc(a, b, c, d)
if err != nil {
return err
}
or
x, y, z, err := someFunc(a, b, c, d)
if err != nil {
log.Printf("some error occurred: %s", err)
}
So we can support ? pseudo-variable, just like _ but with next logic:
if user defines a func, that returns error, the next code will return zero values for any returning variable but last error:
if user defines a func that returns named variables and an error, the next code will return named variables and error:
func someFuncWithErrAndNamedRets() (a string, b int, c []byte, error) {
a = "a string"
b = 0
c = []byte{'0', '1', '2'}
x, y, z, ? := someFunc()
}
if user defines a func that returns named variables and an error, the next code will return named variables and error, but returned values from someFunc() will overwrite a, b and c:
func someFuncWithErrAndNamedOWRets() (a string, b int, c []byte, error) {
a = "a string"
b = 0
c = []byte{'0', '1', '2'}
a, b, c, ? = someFunc()
}
if user defines a func that is not returns any error, the error will be printed and function will return zero values for given types:
Now we should write tons of boilerplate code like
or
So we can support
?
pseudo-variable, just like_
but with next logic: if user defines a func, that returns error, the next code will return zero values for any returning variable but last error:if user defines a func that returns named variables and an error, the next code will return named variables and error:
if user defines a func that returns named variables and an error, the next code will return named variables and error, but returned values from
someFunc()
will overwritea
,b
andc
:if user defines a func that is not returns any error, the error will be printed and function will return zero values for given types: