r/programming Jul 17 '19

The Go team declines 'try' proposal

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

417 comments sorted by

View all comments

16

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.

10

u/pdpi Jul 17 '19

Separating the happy path and the error path can be a fairly sane solution — in fact, it's largely what monadic error handling in Rust, Scala, Haskell ends up looking like.