I am reviewing some code.
I have notice some empty catch blocks. Not a good idea since somethings do not work and you cannot see why.
Is there an easy way to find all empty try catch blocks in a solution?
I am reviewing some code.
I have notice some empty catch blocks. Not a good idea since somethings do not work and you cannot see why.
Is there an easy way to find all empty try catch blocks in a solution?
Thanks to Stefan for the Regex suggestion. I found that the suggested regex does not find catch blocks where the exception is not specified, ie:
I tweaked Stefan's slightly to make the exception brace optional:
Use use the global find dialog, turn on regular expressions and then search for:
Press Ctrl + Shift + F. Expand Find options. Check Use Regular Expressions Paste this regex.
Further expanded the three solutions above to include clauses where the curly brackets aren't on the same line as the catch and where the catch clause contains only single line quotes:
FxCop will find them along with many other potential issues.
Here is a regular expression that finds also catch blocks with only comments inside :