[erlang-questions] Failure semantics of dets:insert_new vs dets:insert
Anthony Ramine
n.oxyde@REDACTED
Sat Jun 28 10:43:05 CEST 2014
Looking at the code, I don't see how dets:insert/2 can ever return an error instead of crashing with badarg.
--
Anthony Ramine
Le 27 juin 2014 à 16:26, Alexei Sholik <alcosholik@REDACTED> a écrit :
> 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
> end
>
> With insert_new it turns to just
>
> dets:insert_new(table, {Key,Value}),
> ok.
>
> IOW, it loses error handling.
>
> Does insert_new() somehow handle any errors that could arise when calling insert()?
>
> --
> Best regards
> Alexei Sholik
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list