3 ms·
Right. Early in learning golang, many people will get tired of typing: ..., err := doStuff() if err != nil { return err } The usual text e
by swdunlop 14y ago
Right. Early in learning golang, many people will get tired of typing:
..., err := doStuff()
if err != nil {
return err
}
The usual text editor features, like templates, reduce the typing, but the point is that the programmer must think, each time, about what they want to do when a function fails. This can become either a really good habit, or a distraction, depending on your perspective and problem domain.
When people say Go poor or no error handling, this is probably what they are complaining about. The fundamental properties offered by try/catch/throw are unpacked by Go into defer, recover and multiple value returns and type switches. Go's designers make the argument that when used thoughtlessly, exceptions encourages error handling antipatterns.