<?xml version="1.0"?>

<ruleset name="Strict Exception Rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../etc/ruleset_xml_schema.xml">
  <description>
These rules provide some strict guidelines about throwing and catching exceptions.
  </description>

   <rule name="AvoidCatchingThrowable"
         message="A catch statement should never catch throwable since it includes errors"
          class="net.sourceforge.pmd.rules.strictexception.AvoidCatchingThrowable"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#LocalVariableCouldBeFinal">
      <description>
This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.
      </description>
      <priority>3</priority>
      <example>
                <![CDATA[
public class Foo {
 public void bar() {
  try {
   // do something
  } catch (Throwable th) {  //Should not catch throwable
   th.printStackTrace();
  }
 }
}
                ]]>
      </example>
    </rule>

<!-- jmv
   <rule name="SignatureDeclareThrowsException"
         message="A signature (constructor or method) shouldn't have Exception in throws declaration"
          class="net.sourceforge.pmd.rules.strictexception.ExceptionSignatureDeclaration"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#LocalVariableCouldBeFinal">
      <description>
It is unclear which exceptions that can be thrown from the methods.
It might be difficult to document and understand the vague interfaces.
Use either a class derived from RuntimeException or a checked exception.
      </description>
      <priority>3</priority>
      <example>
                <![CDATA[
public void methodThrowingException() throws Exception {
}
                ]]>
      </example>
    </rule>
-->

    <rule name="ExceptionAsFlowControl"
          message="Avoid using exceptions as flow control"
          class="net.sourceforge.pmd.rules.design.ExceptionAsFlowControl"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#ExceptionAsFlowControl">
      <description>
          Using Exceptions as flow control leads to GOTOish code.
      </description>
        <priority>3</priority>
      <example>
  <![CDATA[
public class Foo {
 void bar() {
  try {
   try {
   } catch (Exception e) {
    throw new WrapperException(e);
    // this is essentially a GOTO to the WrapperException catch block
   }
  } catch (WrapperException e) {
   // do some more stuff
  }
 }
}
  ]]>
      </example>
    </rule>

<rule name="AvoidCatchingNPE"
    message="Avoid catching NullPointerException; consider removing the cause of the NPE."
    class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#AvoidCatchingNPE">
    <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[
public class Foo {
 void bar() {
  try {
   // do something
   }  catch (NullPointerException npe) {
  }
 }
}
]]>
         </example>
    <priority> 3 </priority>
    <properties>
      <property name="xpath">
        <value>
            <![CDATA[
//CatchStatement/FormalParameter/Type
 /ReferenceType/ClassOrInterfaceType[@Image='NullPointerException']
 ]]>
        </value>
      </property>
    </properties>
  </rule>

  <rule name="AvoidThrowingRawExceptionTypes"
      message="Avoid throwing raw exception types"
      class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#AvoidThrowingRawExceptionTypes">
    <description>
Avoid throwing certain exception types.  Rather than throw a raw RuntimeException, Throwable,
 Exception, or Error, use a subclassed exception or error instead.
    </description>
 <example>
      <![CDATA[
public class Foo {
public void bar() throws Exception {
  throw new Exception();
 }
}
]]>
    </example>
    <priority> 1 </priority>
    <properties>
      <property name="xpath">
        <value>
            <![CDATA[
//AllocationExpression
 /ClassOrInterfaceType[
 @Image='Throwable' or
 @Image='Exception' or
 @Image='Error' or
 @Image='RuntimeException']
 ]]>
        </value>
      </property>
    </properties>
  </rule>

    <rule name="AvoidThrowingNullPointerException"
        message="Avoid throwing null pointer exceptions"
        class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strictexception.html#AvoidThrowingNullPointerException">
      <description>
Avoid throwing a NullPointerException - it's confusing because most people will assume that the
 virtual machine threw it.  Consider using an IllegalArgumentException instead; this will be
 clearly seen as a programmer initiated exception.
      </description>
   <example>
        <![CDATA[
public class Foo {
 void bar() {
  throw new NullPointerException();
 }
}
  ]]>
      </example>
      <priority> 1 </priority>
      <properties>
        <property name="xpath">
          <value>
              <![CDATA[
//AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
   ]]>
          </value>
        </property>
      </properties>
    </rule>

</ruleset>
