logoalt Hacker News

rollcatlast Tuesday at 5:05 PM1 replyview on HN

Snip:

    if err != nil {
        return fmt.Errorf("invalid integer: %q", a)
    }
Snip. No syntax for error handling is OK with me. Spelling out "hey I actually do need a stack trace" at every call site isn't.

Replies

skydhashlast Tuesday at 6:03 PM

You actually don't. In mistakes #52 "Handling an error twice" from the book "100 Go Mistakes and How to Avoid Them" by Teiva Harsanyi, the recommendation is to either return an error to the caller or handle the situation (and maybe logging it). Sometimes you wnat some extra information as to why it's an error, so you wrap it.

Go forces you to be explicit about error handling. Java syntax is not that much better. JavaScript, Kotlin, Swift,... is more about avoiding null pointer exception than proper error handling.

show 1 reply