Here's an article I found that shows the usefulness of .NET decompilers such as Reflector. Jason Bock has an article on AngryCoder showing a situation where the .NET Framework can through an exception while getting the value of a property. He was using ASP.NET to retrieve the HTTP Referrer and found that it was throwing an exception. His code looked like:
if(this.Request.UrlReferrer != null)
{
//Use the property's value.
}
Using a decompilation tool it's clear that the UrlReferrer property is doing some lazy evaluation of a URI member variable that represents the referrer. The problem is that the .NET code is checking for the wrong type of exception. If the URI object experience a problem in its constructor (such as a null or empty referrer value) then the documentations states that a NullArgumentException or a UriFormatException will be thrown. However, the actual code only catches an HttpException:
try
{
if (text1.IndexOf("://") >= 0)
{
this._referrer = new Uri(text1);
}
else
{
this._referrer = new Uri(this.Url, text1);
}
}
catch (HttpException)
{
this._referrer = null;
}
This is a downside of not having Java style exceptions, where each class must declare which exceptions it might throw and the compiler checks that all calling code handles it. Describing the exception in the code is not a foolproof way of doing it.
Jason's article was on .NET 1.0, but it's still a problem in .NET 1.1. Shame, Microsoft, shame ;)