|
|
|
|
|
by tsimionescu
2534 days ago
|
|
The fact that you need to add context to errors usually exacerbates the problem and makes it even harder to read the code. You often end up with err = doThing()
if err! = nil {
return errors.New("Error doing thing", err)
}
This doesn't add any useful information for whoever is reading the code, it's just boilerplate that you learn to skip while reviewing, while hopefully not missing any important thing that does happen on the error path.As for 'programming with the error', I would like to see an actual use case for constantly doing this, and why exceptions would prevent that pattern. The only one I can remember is something highlighted as a 'good practice' by Rob himself: write everything you want to a bufio.Writer, without checking the error messages, and then calling Flush and only then checking if maybe something failed. If this is good, safe, sad-path-first, errors-are-values style... then my taste in programming is obviously bad. Obviously, the same could be achieved with exceptions. |
|
If above is true, then how about:
The end error could then be something for example: I didn't even twist your example, and yet you can already see more information. And with that information, even a user can understand what's going on clearly. So ... more useful?