views:

211

answers:

3

Hi, is there any way to find out all the empty catch blocks inside Java code. I know there are some tools like PMD to do that, but i am using RSA, is there any way we can write a regex to search for empty catch blocks?

Update: i am working on a corporate machine where i cant install new softwares :(

A: 

Something like this:

catch[\s]*\([^\)]*\)[\s]*{[\s]*}

This will return empty catch statements, but not those with comments.

Paul Lammertsma
Don't forget to compile the `Pattern.MULTI_LINE`. And you forgot to exclude comments in the code block.
Aaron Digulla
+1  A: 

Use PMD from the command line, from an Ant script or use Maven to build your projects. This way, you can automatically build and test your deliverables and run tools like PMD or FindBugs.

Aaron Digulla
+2  A: 

The Eclipse Java compiler can be configured to produce warnings (or error message) for empty statements:

Java > Compiler > Errors/Warnings > Empty statement.

You could use the batch compiler (Running the batch compiler) if you do not use eclipse.

But then you could use other Java tools as well. Using a Java library is not a sofware installation. As long as the JRE is not locked by the security manager configuration this should always work.

Thomas Jung
This helped me, of course not the exact way. instead of "empty statement" i used to "undocumented empty block". this actually found all the empty catch blocks.
micheal