#Handling error in one line

3 messages · Page 1 of 1 (latest)

olive moss
#

When is it appropriate to deal with the error in the same line as the call of a method that returns an error?

meager atlas
#

If it just returns an error, I think it's almost always appropriate

#

becomes a different story when it's a tuple, consider:

func blah() (error, int) {
    return nil, 100
}

func main() {
    if err, x := blah(); err != nil { // error, didn't use x within if block
        return
    }

    fmt.Println(x) // error, can't use x here
}