[erlang-questions] Failure semantics of dets:insert_new vs dets:insert

Alexei Sholik alcosholik@REDACTED
Fri Jun 27 16:26:50 CEST 2014

The signature for dets:insert_new is

    insert(Name, Objects) -> ok | {error, Reason}

However, in my use case, I'm using a hash of the value as the key. So I
thought I'd switch to using insert_new because that might be slightly more
efficient (no need to update stored value).

But the signature for insert_new is

    insert_new(Name, Objects) -> boolean()

In this case, false only indicates that a value for the key is already in
the table. What about failure cases of insert()?

With insert() I have this code

   case dets:insert(table, {Key,Value}) of
      ok  -> ok;
      {error, _}=Other -> Other

With insert_new it turns to just

   dets:insert_new(table, {Key,Value}),

IOW, it loses error handling.

Does insert_new() somehow handle any errors that could arise when calling

Best regards
Alexei Sholik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140627/67d283b1/attachment.htm>

More information about the erlang-questions mailing list