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 } } }