Errors
Elixir has three error mechanisms: errors, throws, and exits.
Instead of all these constructs, Elixir's supervisor system is better to just fail fast and restart the app in a known state
Errors
Errors (or exceptions) are used when exceptional things happen in the code.
In Elixir, we avoid using try/rescue
because we don’t use errors for control flow. Try/catch => try/rescue, in practice rarely used b/c tuple with err often used instead
Custom Errors
Throws
throw
and catch
are reserved for situations where it is not possible to retrieve a value unless by using throw
and catch
.
Also uncommon
Exits
When a process dies of "natural causes" (unhandled exceptions), it sends an exit signal
Last updated