Clear, communicative naming is important in code. It helps maintainers and API users understand the intentions for and uses of a unit of code.
Using "exception" in the name of a class that does not extend Exception
or one of its subclasses is a clear violation of the expectation
that a class' name will indicate what it is and/or does.
Noncompliant code example
class FruitException { // Noncompliant; this has nothing to do with Exception
private $expected;
private $unusualCharacteristics;
private $appropriateForCommercialExploitation;
// ...
}
class CarException { // Noncompliant; the extends clause was forgotten?
public function __construct(string message, Throwable cause) {
// ...
Compliant solution
class FruitSport {
private $expected;
private $unusualCharacteristics;
private $appropriateForCommercialExploitation;
// ...
}
class CarException extends Exception {
public function __construct(string message, Throwable cause) {
// ...