[Mono-dev] [PATCH] Uri.IsWellFormedUriString should not throw an exception.

Robert Jordan robertj at gmx.net
Wed Jan 21 12:51:53 EST 2009


Hi Bill,

Bill Holmes wrote:
> Uri.IsWellFormedUriString calls the .ctor which throws an exception.
> The .ctor throwing the exception is expected behavior,
> IsWellFormedUriString throwing is not expected.

> +			try {
> +				Uri uri = new Uri (uriString, uriKind);
> +				return uri.IsWellFormedOriginalString ();
> +			}
> +			catch (UriFormatException) {
> +				return false;
> +			}

I'd rather use Uri.TryCreate () instead of catching exceptions:

Uri uri;
if (Uri.TryCreate (uriString, uriKind, out uri))
	return uri.IsWellFormedOriginalString ();
else
	return false;

Robert



More information about the Mono-devel-list mailing list