[erlang-questions] Vá: How do I elegantly check many conditions?

Attila Rajmund Nohl <>
Tue Mar 24 22:08:36 CET 2009


2009/3/24, Hynek Vychodil <>:
[...]
>
> code
>
> ok = is_new_email1(Email).
>
> doesn't looks like same amount of code
>
> try is_new_email2(Email) catch throw:email_in_use -> email_in_use end.
>
> First one turns return value to exception, second one  turns exception to
> return value. Second one seems more code, does not?

The beauty of execption handling is that you don't have to handle the
exception where it was thrown. So in real code the second would be
something like

checks() ->
 foo(),
 is_new_email(Email),
 bar().

And the catch would be at the call of checks().



More information about the erlang-questions mailing list