This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Maintaining a consistent link between the caught variable and the exception thrown in the corresponding try block brings clarity and predictability. Reassigning the caught variable disrupts this expectation and can lead to confusion. By refraining from these reassignments, developers can know that the variable encapsulates the essence of the original exception.
Non-Compliant Code Examples
publicclassFoo{publicvoidfoo(){try{// do something}catch(Exceptione){e=newNullPointerException();// should not reassign here}}}
Compliant Code Examples
publicclassFoo{publicvoidfoo(){try{// do something}catch(MyExceptione){newError=newRuntimeException();// created a new error variable}}}
1
2
rulesets:- java-best-practices # Rules to enforce Java best practices.