How can I prevent empty try and catch statements?

I’ve seen the new check-in policies, they look good, and I am very interested in the “forbidden patterns policy”.

How can I write a regular expression that say, empty catch statements are not allowed; even if there are comments inside them, like this for example?

Try { do something here}

Catch {}

Or

catch (Exception ex) { ; // do nothing}

How can I also forbid the using of regions, not the automatically generated once, the manually written by developers.

[1006 byte] By [G.T.] at [2008-2-26]
# 1
As-is, the policy actually just looks at the server path of the item, not its contents. This is primarily because policies need to be able to evaluate *fast* since they're evaluated fairly often (sometimes on the UI thread).

If you want to change it to check the contents instead, just find this check in the Evaluate method:

if (forbiddenRegex.IsMatch(pendingChange.ServerItem))

And change to something like this:
string contents = null;
if (File.Exists(pendingChange.LocalItem))
{
contents = File.ReadAllText(pendingChange.LocalItem);
}
if (forbiddenRegex.IsMatch(contents))

You'll most likely want to change the "new Regex" call over in the form class to also specify RegexOptions.Singleline, but that somewhat depends on how you want to use the regex's, so you can play with that.

Let me know if you have problems doing that, I'll wrap it up in a new post "ForbiddenContentPatternsPolicy" or something :)

JamesManning-MSFT at 2007-10-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server – Power Tools & Add-ons...
# 2

To be able to do this, I should know how does C# represent the "try" and "catch" as regular expressions.

Microsoft already implemented c# as regular expressions inside the VS.NET 2003 and 2005 editor, I don’t want to reinvent the wheel :-)

Unfortunately, I can’t find the details of this implementation published anywhere

G.T. at 2007-10-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server – Power Tools & Add-ons...
# 3
Isn't there a Code Analysis rule for this? If not then perhaps a better option would be a custom Code Analysis rule
LeonMayne at 2007-10-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server – Power Tools & Add-ons...

Visual Studio Team System

Site Classified