try catch scope

Wes James comptekki@REDACTED
Tue Jun 29 23:21:12 CEST 2010


What is the scope of try/catch.

I changed the code:

has_query(A) ->
		case length(yaws_api:parse_query(A)) of
			0  -> false;
			_ -> true
		end.
to this

has_query(A) ->
	try
		case length(yaws_api:parse_query(A)) of
			0  -> false;
			_ -> true
		end
	catch
		_ -> false
	end.


because if a user puts in an invalid character in the URL it crashes
parse_query and I want the app to continue without erroring out in the
browser.

Is this because of the level of the error?

For instance if you have the url http://localhost/app?var1=foo1%var2=foo2

in parse_query it tries to do a list_to_integer of "va" with var2
based on how it parses the args list and you can't do that since "va"
doesn't produce a valid integer.  Would the try need to be at the
level of the list_to_integer call?

thx,

-wes


More information about the erlang-questions mailing list