4 ms·
Well, there is one thing forcing you to handle errors, you have to deliberately suppress them or the compiler yells at you. https://play.golang.org/p/3ujNLwOdX
by Symmetry 7y ago
Well, there is one thing forcing you to handle errors, you have to deliberately suppress them or the compiler yells at you.
https://play.golang.org/p/3ujNLwOdXZf https://play.golang.org/p/3ujNLwOdXZf
But explicitly having to handle them versus implicit exception based handling is a tradeoff. Often it isn't clear which exceptions a function might throw unless you've read all the documentation or you're the one who wrote it. When I'm coding my own stuff I'd tend to prefer exceptions but in larger teams I'd tend to prefer explicit handling.
And then there are languages, e.g. Haskell and its Maybe, that manage to combine the best of both worlds.
- stcredzero 7y agoIs there a way in Haskell to have Maybe with an optional callback?
- feadog 7y agoYou mean a CarlyRaeJepsen monad? A "Call Me Maybe?"
- spullara 7y agoYou just replace err with _ and it doesn't care anymore: https://play.golang.org/p/in5pgl11fO7 https://play.golang.org/p/in5pgl11fO7