In a Visual Studio 2010 C# Project, how do I find out if any method is written without having a try-catch block?
Sometimes as a code reviewer, its hard to search function/methods which are not properly written according to code standards esp: without a try-catch block.
I know that the Find option in Visual Studio supports regular expressions. But what’s the regular expression that could perform this job smartly?
Edit (putting the direct answer first): It would actually be easy to use Assembly.ReflectionOnlyLoadFrom, then enumerate the types, and the methods of those types, then for each method body examine the ExceptionHandlingClauses.
Commentary follows:
Red Gate used to offer the Exception Hunter tool for tracking down possible exception issues. As mentioned on that page, it’s been shown that the specific task you have requested (broad searches for any unhandled exception) does not lead to higher quality software even with assistance of automated analysis tools.
If I needed to find a list of all methods without a protected region, I could
simply use one of my experimental assembly loaders (written with relative ease according to ECMA-335) and examine the metadata as described in ECMA-335, Partition II, §25.4.5 and §25.4.6(much easier to use the first part of this answer). If I needed to find a list of these methods for the purpose of adding a protected region to each of them to conform to a coding standard, I would report back that they need to find another developer to do that because I refuse to knowingly and intentionally degrade the quality of software I work on.