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

Jonathan Anderson jonathan.l.anderson at gmail.com
Thu Jan 22 23:37:53 EST 2009


I had submitted a similar patch to this in bugzilla back in November 
that seems to have gone unnoticed.

https://bugzilla.novell.com/show_bug.cgi?id=376692

Jonathan Anderson

Robert Jordan wrote:
> 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
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 


More information about the Mono-devel-list mailing list