diff --git a/docs/pages/pmd/rules/java.md b/docs/pages/pmd/rules/java.md index 92c8d37e80..d3e3e463c0 100644 --- a/docs/pages/pmd/rules/java.md +++ b/docs/pages/pmd/rules/java.md @@ -326,6 +326,7 @@ List of rulesets and rules contained in each ruleset. * [AvoidThrowingNullPointerException](pmd_rules_java_strictexception.html#avoidthrowingnullpointerexception): Avoid throwing NullPointerExceptions. These are confusing because most people will assume that th... * [AvoidThrowingRawExceptionTypes](pmd_rules_java_strictexception.html#avoidthrowingrawexceptiontypes): Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,Excep... * [DoNotExtendJavaLangError](pmd_rules_java_strictexception.html#donotextendjavalangerror): Errors are system exceptions. Do not extend them. +* [DoNotExtendJavaLangThrowable](pmd_rules_java_strictexception.html#donotextendjavalangthrowable): Extend Exception or RuntimeException instead of Throwable. * [DoNotThrowExceptionInFinally](pmd_rules_java_strictexception.html#donotthrowexceptioninfinally): Throwing exceptions within a 'finally' block is confusing since they may mask other exceptions or... * [ExceptionAsFlowControl](pmd_rules_java_strictexception.html#exceptionasflowcontrol): Using Exceptions as form of flow control is not recommended as they obscure true exceptions when ... * [SignatureDeclareThrowsException](pmd_rules_java_strictexception.html#signaturedeclarethrowsexception): Methods that declare the generic Exception as a possible throwable are not very helpful since the... diff --git a/docs/pages/pmd/rules/java/strictexception.md b/docs/pages/pmd/rules/java/strictexception.md index bb3ee1265e..fd7ec02504 100644 --- a/docs/pages/pmd/rules/java/strictexception.md +++ b/docs/pages/pmd/rules/java/strictexception.md @@ -5,7 +5,7 @@ permalink: pmd_rules_java_strictexception.html folder: pmd/rules/java sidebaractiveurl: /pmd_rules_java.html editmepath: ../pmd-java/src/main/resources/rulesets/java/strictexception.xml -keywords: Strict Exceptions, AvoidCatchingThrowable, SignatureDeclareThrowsException, ExceptionAsFlowControl, AvoidCatchingNPE, AvoidThrowingRawExceptionTypes, AvoidThrowingNullPointerException, AvoidRethrowingException, DoNotExtendJavaLangError, DoNotThrowExceptionInFinally, AvoidThrowingNewInstanceOfSameException, AvoidCatchingGenericException, AvoidLosingExceptionInformation +keywords: Strict Exceptions, AvoidCatchingThrowable, SignatureDeclareThrowsException, ExceptionAsFlowControl, AvoidCatchingNPE, AvoidThrowingRawExceptionTypes, AvoidThrowingNullPointerException, AvoidRethrowingException, DoNotExtendJavaLangError, DoNotExtendJavaLangThrowable, DoNotThrowExceptionInFinally, AvoidThrowingNewInstanceOfSameException, AvoidCatchingGenericException, AvoidLosingExceptionInformation --- ## AvoidCatchingGenericException @@ -310,6 +310,30 @@ public class Foo extends Error { } ``` +## DoNotExtendJavaLangThrowable + +**Since:** PMD 6.0 + +**Priority:** Medium (3) + +Extend Exception or RuntimeException instead of Throwable. + +``` +//ClassOrInterfaceDeclaration/ExtendsList/ClassOrInterfaceType + [@Image="Throwable" or @Image="java.lang.Throwable"] +``` + +**Example(s):** + +``` java +public class Foo extends Throwable { } +``` + +**Use this rule by referencing it:** +``` xml + +``` + ## DoNotThrowExceptionInFinally **Since:** PMD 4.2 diff --git a/pmd-java/src/main/resources/rulesets/java/strictexception.xml b/pmd-java/src/main/resources/rulesets/java/strictexception.xml index 7efab2baf1..b129dd5718 100644 --- a/pmd-java/src/main/resources/rulesets/java/strictexception.xml +++ b/pmd-java/src/main/resources/rulesets/java/strictexception.xml @@ -243,6 +243,31 @@ public class Foo extends Error { } ]]> + + +Extend Exception or RuntimeException instead of Throwable. + + 3 + + + + + + + + + + + + + + 1 + + + + + 1 + + + + + 0 + + +