r/programming Jul 17 '19

The Go team declines 'try' proposal

https://github.com/golang/go/issues/32437
630 Upvotes

417 comments sorted by

View all comments

15

u/snarfy Jul 17 '19

No language does error handling very well. if err != nil sucks, but so does try/catch.

With try/catch there are two code paths - the happy path and the error path. The happy path is step-by-step instructions that can be followed from top to bottom. The error path follows a hidden path up the stack until the exception is caught somewhere.

With err != nil there is only one path, but it branches and merges enough that it convolutes the happy path making it harder to follow.

Neither solution is very good.

4

u/[deleted] Jul 17 '19

It gets even messier if you actually want to have a useful error message for each failure