[erlang-questions] Idiomatically handling multiple validation checks

Fred Hebert <>
Wed Dec 7 01:22:50 CET 2016

On 12/07, Richard A. O'Keefe wrote:
>* Exceptions are meant for recoverable errors;
>  but many errors are not recoverable!
>* A bug is an error the programmer didn't expect;
>  a recoverable error is an expected condition,
>  resulting from programmatic data validation.
>* Treating bugs and recoverable errors homogeneously
>  creates reliability problems.

That's one of the interesting things in Erlang; not all exceptions are 

- throws are recoverable non-local returns
- errors are usually bugs
- exits signal that the current process cannot keep going
- try ... catch does not mix them up unless especially asking for it 
  (with a _:Whatever match)

Their semantic distinction is something I find useful in every day 
systems in terms of how these things are handled for Erlang.

raise an error for bugs, raise an exit for dead ends where the process 
does not make sense, raise an exception for cumbersome non-local returns 
(which then should get transformed to {error, Reason} past the 
functional interface).

If you want to turn a recoverable error into a bug, you just match {ok, 
Res} = Exp, and if it's bad, you now get a badmatch.

That kind of dynamic is not something I remember seeing in multiple 
languages before.

More information about the erlang-questions mailing list