Raising an Exception
Explore how to raise and handle exceptions in Elixir, including the use of the raise function, try blocks with rescue and catch clauses, and managing different error types. Understand Elixir's approach to errors and process supervision, helping you write robust and fault-tolerant applications.
We'll cover the following...
Elixir (like Erlang) takes the view that errors should normally be fatal to the processes in which they occur. A typical Elixir application’s design involves many processes, which means the effects of an error will be localized. A supervisor will detect the failing process, and the restart will be handled at that level.
For that reason, we won’t find much exception-handling code in Elixir programs. Exceptions are raised, but we rarely catch them. Use exceptions for things that are exceptional— that is, things that should never happen.
Implementation
We can raise an exception using ...