[erlang-questions] using catch - getting error

Hynek Vychodil hynek@REDACTED
Mon Jul 12 10:29:20 CEST 2010


Try use lists:keyfind/2 instead. proplists may be do little bit more
than you need and is this slower.

On Sat, Jun 26, 2010 at 12:16 AM, Wes James <comptekki@REDACTED> wrote:
> I have this function:
>
> lk(Key, L) ->
>    {_, Error} = (catch {value, {_,Vale}} = lists:keysearch(Key, 1, L)),
>    case length(Error) of
>        0 ->
>                Val = Vale;
>        _ ->
>                Val = 0
>    end,
>    Val.
>
> A list (L) should have all the keys necessary when lk is called, but
> if the key does not exist, the keysearch will throw an exception.  I'm
> trying to catch that, but I get the error Vale is unsafe. What is the
> proper way to do this?
>
> If the key exists, then put it in Val and return Val, if the key does
> not exist, catch the error and set Val to 0.
>
> How should this be done?
>
> thx,
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com


More information about the erlang-questions mailing list