[erlang-questions] Re: try catch scope

Wes James <>
Thu Jul 1 00:43:31 CEST 2010


On Wed, Jun 30, 2010 at 8:17 AM, Raimo Niskanen
<> wrote:
> On Wed, Jun 30, 2010 at 07:33:39AM -0600, Wes James wrote:
>> Mangus,
>>
>> Thanks! This is much better!
>>
>> has_query(A) ->
>>       try
>>               yaws_api:parse_query(A) /= []
>>       catch
>>               _:_ -> false
>>       end.
>>
>> -wes
>
> This might be even clearer (separating the right and wrong cases):
>
> has_query(A) ->
>    try yaws_api:parse_query(A) of
>        [] -> false;
>        _ -> true % Were you supposed to return true for this case?
>    catch
>        error:_ -> false % Only cathes runtime errors, not exit/1.
>    end.
>


Thanks.  This works too.  Bottom line, is I want to show the default
search page even if the parse_query call throws an error.  Maybe
someone is trying to insert bad chars or such in to the URL to try to
reveal something or even hack the system, etc.

thx,

-wes


More information about the erlang-questions mailing list