[erlang-questions] try catch scope

Sergey Samokhin prikrutil@REDACTED
Tue Jun 29 23:46:07 CEST 2010


> 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