[erlang-questions] errors in gb_sets and gn_trees

Robert Virding <>
Fri Sep 17 03:05:41 CEST 2010


It should be erlang:error/1 as it is. Erlang:error/1 is intended for
signaling errors, in this case a {key_exists,Key} error, while
erlang:throw/1 was intended for throwing non-local returns not
throwing errors. Throws and errors are handled differently in
catch/try. They also result in different exit reasons if not caught at
all, for erlang:error the exit value is the actual error reason
together with the call stack, while for erlang:throw it is a 'nocatch'
error.

Robert

2010/9/16 Kostis Sagonas <>:
> Modules gb_sets and gb_trees each define an insert/2 function whose
> documentation (for gb_sets) reads:
>
>  insert(Element, Set1) -> Set2
>     Types:
>       Element = term()
>       Set1 = Set2 = gb_set()
>  Returns a new gb_set formed from Set1 with Element inserted. Assumes
>  that Element is not present in Set1.
>
> and whose code reads:
>
>  insert(Key, Val, {S, T}) when is_integer(S) ->
>    S1 = S+1,
>    {S1, insert_1(Key, Val, T, ?pow(S1, ?p))}.
>
>  insert_1(Key, Value, {Key1, V, Smaller, Bigger}, S) when Key < Key1 ->
>    case insert_1(Key, Value, Smaller, ?div2(S)) of
>  ....
>  insert_1(Key, _, _, _) ->
>    erlang:error({key_exists, Key}).
>
> Should the last line be a call to erlang:error/1 or to erlang:throw/1 ?
>
> Kostis
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list