configure checkstyle to ignore an empty catch block
checkstyle, eclipse, java
Solution
The general question of how to tailor Checkstyle is ansered by this Question:
- How to disable a particular checkstyle rule for a particular line of code?
The Checkstyle documentation for tailoring the checking of blocks is here:
- http://checkstyle.sourceforge.net/config_blocks.html
And the specific style configuration you need is:
<module name="EmptyBlock">
<property name="option" value="text"/>
<property name="tokens" value="LITERAL_CATCH"/>
</module>
Problem
in my team we use checkstyle to improve our coding standards, but now we came across a rule which could be improved. The Empty Block rule gives us a warning about an empty catch block (without java code and without comment), but with the standard configuration it generates also a warning if the block contains a comment. e.g. The two should not result a warning: ``` try { // some code } catch (NumberFormatException ignore) { // ignore } try { // some code } catch (NumberFormatException e) { logger.debug("some debug"); } ``` This should result a warning: ``` try { // some code } catch (NumberFormatException ignore) { } ``` How can we improve checkstyle to give us only a warning, if no comment and no java code is in the catch block? I looked for a solution, but I stackoverflow and google didn't have any. Can someone help me?