Search code examples
javaintellij-ideapmdsuppress-warnings

parameter to suppresswarnings for catching `Exception` in IntelliJ Idea


I am using PMD and checkstyle and using code like below

public void testMethod() {
try {
            // do something
            } catch (Exception e) {
                logger.error("Error updating benchmark {} state", benchmarkId, e);
            }
}

But its failing during quality check as testmethod is catching Exception. I want used @SuppressWarnings("PMD.SignatureDeclareThrowsException") but its not working and tried searching what should be the proper annotation to handle it but couldn't find it.

Let me know what should be proper PMD annotation to suppress warning for catching exception in Intellij Idea.


Solution

  • SignatureDeclareThrowsException is the rule that forbids doing method declarations such as void myMethod() throws Exception.

    Here, you are probably being reported of AvoidCatchingGenericException on this block (check this). Therefore, you should probably use @SuppressWarnings("PMD.AvoidCatchingGenericException") instead.