In Erlang, it’s idiomatic to communicate errors via pattern matching and the use of tagged tuples. This approach makes it easy to see which functions return errors and to handle them using the same language constructs employed for other, non-error tasks.
In Erlang, we use pattern matching extensively for error handling. The case expression is used to match on the return value of functions and handle different cases accordingly.
To run this program, save it as errors.erl and use the Erlang shell:
Erlang’s approach to error handling is quite different from languages that use exceptions. Instead of try-catch blocks, Erlang encourages the use of pattern matching and the “let it crash” philosophy, where processes are allowed to fail and are restarted by supervisors.