3 ms·
To be fair, you wouldn't do that in JS because exceptions have a stack trace, so you don't need to add the context on every return. The downside is that since
by thiht 3y ago
To be fair, you wouldn't do that in JS because exceptions have a stack trace, so you don't need to add the context on every return.
The downside is that since you don't "need" to catch your exceptions, you don't think about them. That's one thing I really like with Go, errors are in my face all the time, so I have to think about them. Even if I write the infamous
if err != nil {
return err
}
at least I do it consciously. And when I or my colleagues read it 2 months later, we know from reading that this can return an error, and we see clearly how it was handled, so we can think about it and visually see if it was handled correctly.
Reviewing and reading code with exceptions is a nightmare, because you have no idea if errors were handled correctly. On every call you have to guess if it throws or not.