This rule identifies when exceptions are raised within a catch block but are not relevant to the exception parameter specified in the catch block. This can result in the original exception’s stack trace information being lost, which leads to throwing less detailed exceptions.
Non-Compliant Code Examples
publicclassFoo{voidfoo(){try{Integer.parseInt("foo");}catch(Exceptione){thrownewException(e.getMessage());// only throwing the message here}}}
Compliant Code Examples
publicclassFoo{voidfoo(){try{Integer.parseInt("foo");}catch(Exceptione){thrownewException(e);// sending the full exception at least}}}
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- java-best-practices # Rules to enforce Java best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines