Error handling vs pattern matching

If using Exceptions is discouraged in favour of pattern matching, why does part_binary throw an ArgumentError?
Is it for historical reasons or are there situations where exceptions are preferred?

Usually you have to differ between failures which can be acted upon on code and those that can’t.

If I can do more after failing (or have to do more!) then one usually pattern matches and handles errors. If the error though means, that all I can do is throw away the computation and ask for new, correct input, then usually an exception is used to bring the process down as fast as possible such that a supervisor can do is job.

Erlang Oddities - Brujo Benavides: Handing Errors

goes into the subtle differences between the various error mechanisms - (and that throwing a value isn’t one of them - it’s simply a non-local return that expects to be caught).

Erlang Battleground


Makes sense! Thanks guys! I’ll look check out the links as well. :slight_smile: