<p>This depends a bit in what you're trying to achieve. Do you need a valid result? Or would some kind of default value be sufficient? In the later case, you could then also provide a get_contact(Email, Default) that returns the default value if none was found in the db.</p>
<p>If you require a valid result to appear in your db, then it could still depend on the rest of your app. Is that something normal you need to be able to react on? If yes, well, then you need to code for it. If not, then you might want to consider it an "exceptional" occurrence and simply crash the process and let the supervisor clean things up.</p>
<p>HTH,<br>
Robby<br>
</p>
<div class="gmail_quote">On Jul 16, 2015 9:03 PM,  <<a href="mailto:lloyd@writersglen.com">lloyd@writersglen.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I have several functions that look like this:<br>
<br>
get_contact(Email) -><br>
  open_db(),<br>
  Result = dets:lookup(?contacts, Email),<br>
  close_db(),<br>
  Result.<br>
<br>
The implication is that the function returns and empty list, [], if it fails to find a record, otherwise it returns a list containing the record.<br>
<br>
This makes it easy to distinguish the failure-to-return a record condition, but means that every function that depends up on get_contact/1 needs to do so and know what to do in that case. But that begins to feel like defensive programming.<br>
<br>
I can see several ways of dealing with this problem, but it occurs to me that there must be a conventional approach. What might be... what?<br>
<br>
Thanks,<br>
<br>
LRP<br>
<br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>