Idiomatically indicating failure in Erlang

Andrew Thompson andrew@REDACTED
Wed Jun 3 01:37:28 CEST 2009


So, today I was working on some code (a RFC204{5,6,7} parser) in erlang,
and I was trying to figure out the best way to indicate various parse
failures;  either ones that are fairly immediate (no MIME-Version
header) or ones that are buried way down in some dark corner of the
body.

This reminded me that I've never been sure what the "good" way to
indicate failure in Erlang is - do I use throw(), error()
or what? Do I just return a tagged tuple like {error, Reason}.

If I use a tagged tuple, should I avoid bloating the atom table and use
a string or should I use an atom like most of erlang's stdlib does? If I
use an atom, should I re-use one that the stdlib already uses or be more
descriptive (eg. missing_mime_boundary).

If I use throw/error, should I use an new atom, an existing one or a
more descriptive term? Should I use throw internally to get back to the
top level of my parser and then use a tagged return value?

I'm just looking to get some thoughts on this since I couldn't find any
hint of a consensus on this when googling and it's always bothered me.

Thanks,

Andrew


More information about the erlang-questions mailing list