5 ms·
Why doesn't GO have a try-catch blocks? Every file I see have dozens similar lines: if err != nil { log.Fatal(err) } In C# I can just log error on one plac
by jjjeii3 6y ago
Why doesn't GO have a try-catch blocks? Every file I see have dozens similar lines:
if err != nil {
log.Fatal(err)
}
In C# I can just log error on one place and transaction will be automatically rolled back. Much less code.
- sketchyj 6y agoGo made the design decision to encourage checking for errors where they occur instead of catching exceptions somewhere down the line.
- proyb 6y agoThere are years of discussion on error handling topics or you could use a package to simplify your code: https://itnext.io/golang-error-handling-best-practice-a36f47b0b94c https://itnext.io/golang-error-handling-best-practice-a36f47...
- ibraheemdev 6y agoThere have been tons of discussions and proposals regarding error handling boilerplate [0][1], and the general consensus is that go developers like the explicitness of `if err != nil` and just want to leave it be [2] [0]: https://github.com/golang/go/issues/32437 https://github.com/golang/go/issues/32437 [1]: https://github.com/golang/go/issues/32804 https://github.com/golang/go/issues/32804 [2]: https://github.com/golang/go/issues/32825 https://github.com/golang/go/issues/32825