I send httpRequest and get httpResponse in a try block. Now I really do not care what type of exception do I get for several reason.
try
{
var request = WebRequest.Create(new Uri("MyUrl")) as HttpWebRequest;
request.GetResponse();
}
catch(Exception)
{
}
FxCop wants me to give specific exception so in my case I need to create several catch blocks as follows:
NotSupportedException
ArgumentNullException
SecurityException
InvalidOperationException
ProtocolViolationException
NotSupportedException
WebException
How can I tackle this warning and avoid writing these many catch blocks at the same time?
fxCop warnings are suggestions, not mandates.
In other words, you’re free to use your judgment as to whether or not to follow the guidelines and suggestions made by fxCop.
This particular suggestion is there because it’s probable that you’d want to handle different types of errors differently. If that’s not the case, you can ignore this rule so it doesn’t clutter up your warnings list.
You know your business rules and coding standards better than fxCop. It’s just making suggestions based on best practices that may or may not apply to your particular situation.
More info can be found here: http://msdn.microsoft.com/en-us/library/bb429303(VS.80).aspx