1.2.477. Forgotten Thrown

This rule reports when an exception is instantiated, but not thrown. Often, this is a case of forgotten throw.

<?php

class MyException extends \Exception { }

if ($error !== false) {
    // This looks like 'throw' was omitted
    new MyException();
}

?>

1.2.477.1. Suggestions

  • Remove the instantiation expression.

  • Add the throw to the new expression.

1.2.477.2. Specs

Short name

Exceptions/ForgottenThrown

Rulesets

All, Analyze, Changed Behavior

Exakat since

0.10.2

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

High

Features

throw, exception

Available in

Entreprise Edition, Exakat Cloud