Menu

Custom PMD Rule that a method should have try catch block statements

Developers
2020-12-10
2021-01-08
  • Divya Amilineni

    Divya Amilineni - 2020-12-10

    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!

     
  • Divya Amilineni

    Divya Amilineni - 2020-12-10

    and the ruleset is also attached . Please help.

     
  • Andreas Dangel

    Andreas Dangel - 2021-01-08

    Thanks for the question. Would you mind to create this question in our new discussions place at github? https://github.com/pmd/pmd/discussions

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.