Throw or return a tuple
Ulf Wiger
ulf@REDACTED
Sat Aug 13 11:59:58 CEST 2005
Den 2005-08-13 10:19:47 skrev Bjorn Gustavsson <bjorn@REDACTED>:
> Another example, any API that would force you to catch exceptions
> just to be able to successfully end a loop is WRONG. (E.g. if
> the queue module would throw an execption when trying to remove an
> element from an empty queue, or if end of file would cause an exception
> when reading from a file.)
I think another good rule is to think through what the
user is supposed to do in case a function can't do its
job. A good example is timer:send_after/3. I've always
wondered what would be appropriate to do when it returns
{error, Reason}. If I can't start a timer, most likely it's
due to an error in the way I'm calling the function, or
because system resources are exhausted. Either way, it
seems fairly difficult to continue. This would have been
a good place to throw an exception rather than to try to
return a "user-friendly" value.
/Uffe
--
Ulf Wiger
More information about the erlang-questions
mailing list