views:

47

answers:

3

Hi,

I am search a way to disable usage (**throw new exception **) of specific exception in our c# solution. If can I configure c# compiler and show compiled error if somebody try to throw a specific exception or, maybe, can I call a utility and analyze compiled binaries and show message if the specific exception was raises in our solution?

I am not look run-time solutions. I want to check in "development" time.

Igor.

+3  A: 

You may consider adding a custom rule(Warning/Error) to the FxCop and then build the solution after adding the FxCop project file into your solution.

Siva Gopal
A: 

Give Gendarme a look; I'm not sure how trivial it is to write a new rule that can do what you want, but I'm hoping it would be easy enough. Failing that, check out StyleCop.

Noon Silk
+1  A: 

If the exception in question is your own exception, you can decorate the exception class with the Obsolete attribute. Then the compiler will show a warning whenever the class is used.

[Obsolete("MyException is obsolete. Please use MyOtherException instead")]
public class MyException : Exception
{
}
0xA3