Question

Java requires that you catch all possible exceptions or declare them as thrown in the method signature. This isn't the case with C# but I still feel that it is a good practice to catch all exceptions. Does anybody know of a tool which can process a C# project and point out places where an exception is thrown but not caught?

Was it helpful?

Solution

Check out the ExceptionFinder plug-in by Jason Bock for the .NET Reflector. It does just what you are looking for. Here's a screeny:

Check it out on CodePlex

OTHER TIPS

There is a R# plug-in that analyses thrown exceptions. http://exceptionalplugin.codeplex.com/

Red-Gate software has a product called Exception Hunter which should do that.

Edit: This product has been discontinued by Red-Gate software.

If you are using C# for a web application then you can use ELMAH which shows a list of all the handled and unhandled exceptions.

Just download ELMAH and plug it in. It is FREE!

Don't catch them in individual methods, unless you need to, setup a global handler.

Application.ThreadException += new ThreadExceptionEventHandler( Application_ThreadException );

private static void Application_ThreadException( object sender, ThreadExceptionEventArgs e)
{ 
       dispatchException( e.Exception );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top