When should an Elixir function return an error tuple, and when should it raise? Paweł Świątkowski sorts the language’s failure signals into practical categories: tagged tuples for expected problems, exceptions for programmer mistakes or infrastructure failures, and exits and throws for process and control-flow signals. The distinction matters because each one calls for a different response—and rescuing everything can hide bugs rather than handle them.
The article shows how to model error reasons with atoms, document them in typespecs, and use custom exceptions when needed. It also demonstrates
rescueandcatch, including the difference between:error,:exit, and:throw. The useful takeaway is a clear rule of thumb: make anticipated failures part of a function’s API, and reserve exceptions for situations that genuinely break the expected flow.
continue reading onwww.honeybadger.io
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.