DEV Community

Alfredo Motta
Alfredo Motta

Posted on

To raise or not to raise exceptions, and the art of designing return values

Each time we call a function that’s meant to perform some operation that could succeed or fail we are always left with the same dilemma. What should be the return value? Should I return nil if a failure happened? Or I should throw an exception? What does failure means anyway?

Like every interesting question, the answer is it depends. In this blog post, I’ll bring clarity to the discussion and present what are the tradeoffs involved and how to choose between the existing alternatives.

Read the full story here

Top comments (0)