<?xml version="1.0" ?>
<ruleset name="throwable">
  <description>Prevents Raw Throwables and NPE</description>

  <rule name="CatchNullPointerException" message="Avoid catching NullPointerException; consider removing the cause of the NPE." class="net.sourceforge.pmd.rules.XPathRule">
    <description>
      Code should never throw NPE under normal circumstances.  A catch block may hide the original error, causing other more subtle errors in its wake.
    </description>
    <example>  <![CDATA[
try {
  ...
} catch (NullPointerException npe) {
  ...
}
]]>
         </example>
    <priority> 3 </priority>
    <properties>
      <property name="xpath">
        <value>  <![CDATA[//TryStatement/FormalParameter/Type/Name[@Image='NullPointerException']]]>  </value>
      </property>
    </properties>
  </rule>

  <rule name="ThrowRawThrowable" message="Avoid throwing Throwable. Subclass Exception or Error." class="net.sourceforge.pmd.rules.XPathRule">
    <description>Avoid throwing a raw Throwable, Exception, or Error.  Use a subclassed exception or error.</description>
 <example>
      <![CDATA[
throw new Exception();
]]>    
    </example>    
    <priority> 1 </priority>   
    <properties>
      <property name="xpath">
        <value>  <![CDATA[//AllocationExpression/Name[@Image='Throwable' | @Image='Exception' | @Image='Error']]]>  </value>
      </property>
    </properties>
  </rule>

  <rule name="ThrowRawRuntimeException" message="Avoid throwing RuntimeException." class="net.sourceforge.pmd.rules.XPathRule">
    <description>Avoid throwing a raw RuntimeException.  Use a subclassed RuntimeException.</description>
    <example>
      <![CDATA[
throw new RuntimeException();
]]>    
    </example>    
    <priority> 1 </priority>
    <properties>
      <property name="xpath">
        <value>  <![CDATA[//AllocationExpression/Name[@Image='RuntimeException']]]>  </value>
      </property>
    </properties>
  </rule>  
  
  <rule name="ThrowNullPointerException" message="Avoid throwing NullPointerException." class="net.sourceforge.pmd.rules.XPathRule">
    <description>Avoid throwing a NullPointerException.  Use IllegalArgumentException or IllegalStateException.</description>
    <example>
      <![CDATA[
throw new NullPointerException("Null parameter");

is confusing because most people will assume that the VM threw NPE.  Consider 
using InvalidArgumentException("Null parameter") which will be clearly seen as
a programmer initiated exception.
]]>    
    </example>    
    <priority> 1 </priority>
    <properties>
      <property name="xpath">
        <value>  <![CDATA[//AllocationExpression/Name[@Image='NullPointerException']]]>  </value>
      </property>
    </properties>
  </rule>  
   
</ruleset>
