![JAR search and dependency download from the Maven repository](/logo.png)
resources.report.rules.pmd.ExceptionsShouldHaveAMessage.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
ExceptionsShouldHaveAMessage
ExceptionsShouldHaveAMessage
All exceptions should have a message, to help in problem diagnosis.
TODO: This only covers the no-arg constructor; there doesn't seem to be a way of
checking the type of a parameter being passed in. For example, the following
will pass:
throw new RuntimeException(someOtherException).
This rule is defined by the following XPath expression:
//AllocationExpression
[ClassOrInterfaceType[ends-with(@Image,'Exception')]]
[count(Arguments/ArgumentList) = 0]
Example:
class Foo
{
public void doSomething(int x, int y)
{
if (x <= 0)
{
throw new IllegalArgumentException(); // Bad
}
else if (y <= 0)
{
throw new IllegalArgumentException("y must be greater than 0"); // Better
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy