I am using .NET 4.0 with VS2010. In my current application (not written by me), I found that there are some many codes like
Try
' do something '
Catch e As Exception
' do nothing about the exception. no logging and no re-throw... =o=!!! '
End Try
My question is how to find this kind of "eaten" exception in the whole application.
Thanks!
Edit: Sorry th开发者_Go百科at I should state that the Catch block is not empty always. Sometimes it could be Return False
, Return Nothing
, Return
, Return 0
, Return ""
...
Run FxCop over the assemblies involved. Look for violations of rule CA1031.
Alternatively you can use this regex on your source code:
catch:b*\([^)]*\):b*\{:b*\}
Use ReSharper(trial of it should be available).
It will warn you about places where you declare but don't handle your exceptions.
http://www.jetbrains.com/resharper/
From Visual Studio, go to "Debug" > "Exceptions", then click the check box "Thrown" under "Common Language Runtime Exceptions". Now when you attach the debugger to your app, it will stop for all exceptions even if they are caught.
As @RoadWarrier pointed out, you can use FxCop which does analysis of the compiled code. Similar to FxCop you can use StyleCop which does the static code analysis of the source code. If you have resharper, you can use StyleCop for Resharper add in which will give real time code analysis as you type the lines of code.
Good that you got application source where you can find the eaten exception. We had to deal with dlls which eats exception during production stage and we are using a exception catcher tool built using MDbgCore.dll
精彩评论