Friday, December 31, 2004

One Issue on FxCop

One rule about catching exceptions is that you should catch a specific exception rather than a general one such as Exception or SystemException. With this rule, FxCop will show a critical error if you catch an Exception or a SystemException.

I'd like to catch an Exception in one case. If I write try/catch blocks, I first try to catch specific exceptions. In some cases, I'm not sure if my specific exceptions cover all the exceptions and I don't want that an uncovered exception faults out the method. In that kind of cases, I catch an Exception as my final catch. Breaking the rule like this is very useful if my method is in an infinite loop.

I'd like to see that FxCop treats my cases differently. If FxCop finds an Exception or SystemException, then it should check if a specific exception is catched before the general catching. If it does, then FxCop should display a warning instead of a critical error.