Custom PMD Rule that a method should have try catch block statements
A source code analyzer
Brought to you by:
adangel,
juansotuyo
Hi,
I am new to PMD. I tried XPATH Expression to generate XML. Below is the XML
<rule message="User Try Catch Statements" name="MethodShouldContainTryCatch" language="apex" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Use try Catch Statements in Every Method
</description>
<priority>3</priority>
<properties>
<property name="version" value="1.0 compatibility">
<property name="xpath">
<value>
<![CDATA
//ClassOrInterfaceBodyDeclaration//MethodDeclaration[count(..//TryStatement)<1 and count(..//CatchStatement)<1
]]>
</value>
</property>
</property></properties>
</rule>
I have added the above rule in rule set other rules are working fine except this rule.
and below is the Expression
//ClassOrInterfaceBodyDeclaration//MethodDeclaration[count(..//TryStatement)<1]
Can you please help me?
Thank you!
and the ruleset is also attached . Please help.
Thanks for the question. Would you mind to create this question in our new discussions place at github? https://github.com/pmd/pmd/discussions