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

ryeguy <>
Fri Mar 20 15:43:38 CET 2009


I actually like that one the best. It's cleanest, and simplest. I
actually thought about something like this, but my mind is still
clouded from other evil languages, where exceptions should be used for
"exceptional" situations (exluding Python).

Is exception handling cheap in Erlang?

On Mar 20, 10:34 am, Paul Fisher <> wrote:
> Hynek Vychodil wrote:
> > One of Joe's suggestion: program success case code separated from error
> > handling. You can make it in this way
>
> > create_user(Email, UserName, Password) ->
> >   try
> >     ok = new_email(Email),
> >     ok = valid_user_name(UserName),
> >     ok = new_user(UserName),
> >     ok = strong_password(Password),
> >     ...
> >     _create_user(Email, UserName, Password)
> >   catch
> >     error:{badmatch, email_in_use} -> do_something();
> >     error:{badmatch, invalid_user_name} -> do_something();
> >     error:{badmatch, user_exists} -> do_something();
> >     error:{badmatch, weak_password} -> do_something();
> >     ...
> >   end.
>
> +1 Bravo!
>
> --
> paul
>
> _______________________________________________
> erlang-questions mailing list
> ://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list