[erlang-questions] try catch scope

Wes James <>
Wed Jun 30 00:17:02 CEST 2010


Thank you Sergey and Jesper for your responses. I went back and looked at:

http://www.erlang.org/doc/reference_manual/expressions.html#id2275780
and
http://www.erlang.org/doc/reference_manual/errors.html

to see how _:_ works.  There is no mention of this on these pages.  Is
_:_ the same as {_,_}?  Is there a doc on what _:_ is?

thx, again,

-wes

On Tue, Jun 29, 2010 at 3:46 PM, Sergey Samokhin <> wrote:
>> has_query(A) ->
>>        try
>>                case length(yaws_api:parse_query(A)) of
>>                        0  -> false;
>>                        _ -> true
>>                end
>>        catch
>>                _ -> false
>>        end.
>
> For this function to catch exceptions of all possible types (error,
> exit and throw) you need to use "_:_" pattern instead of just "_"
> (which will catch only 'throw' exceptions):
>
> has_query(A) ->
>       try
>               case length(yaws_api:parse_query(A)) of
>                       0  -> false;
>                       _ -> true
>               end
>       catch
>               _:_ -> false % <----- Here "_" has been replaced by "_:_"
>       end.
>
> --
> Sergey Samokhin
>


More information about the erlang-questions mailing list