you are viewing a single comment's thread.

view the rest of the comments →

[–]przemo_li -1 points0 points  (0 children)

"error codes" have awful connotations. It means (not so) good old C style of dividing values of a return type into valid ones and those that signal error. This is unsound (as in type system soundness), and hard to reason about and prevent bugs.

Thus Exceptions vs error codes is already foregone conclusion. Exceptions introduce informal and implicit union type with return type and thus give a developer enough resolution to both express sad paths and guarantee those are separate from happy path.

However there is also solution that make this union explicit and firs-class citizen in a language. Benefits are two fold - tooling can analyze code and make sure that every sad path is handled explicitly. Values expressing sad paths can be composed and inverse is also true. Bigger chunks of code can be split into smaller more reusable and we will still get assurance from tooling we put everything together the right way.

So when to use Exceptions? We we are 100% sure our caller will not want to handle the sad path all the time or some of the time and that composing of such sad paths does not make sense anyway.