logoalt Hacker News

ziml77last Tuesday at 5:34 PM1 replyview on HN

They admit it's contrived, but this isn't very convincing

    func printSum(a, b string) error {
        x, err := strconv.Atoi(a)
        if err != nil {
            return fmt.Errorf("invalid integer: %q", a)
        }
        y, err := strconv.Atoi(b)
        if err != nil {
            return fmt.Errorf("invalid integer: %q", b)
        }
        fmt.Println("result:", x + y)
        return nil
    }
It's not adding anything that the Atoi function couldn't have reported. That's a perfect case for blindly passing an error up the stack.

Replies

nasretdinovlast Tuesday at 6:41 PM

It does, it says which one of the two integers was incorrect

show 1 reply