1.2.1271. Unresolved Catch

Catch clauses do not check for Exception existence.

Catch clauses check that the emitted expression is of the requested Class, but if that class doesn’t exist in the code, the catch clause is always false. This is dead code.

<?php

try {
    // doSomething()
} catch {TypoedExxeption $e) { // Do not exist Exception
    // Fix this exception
} catch {Stdclass $e) {        // Exists, but is not an exception
    // Fix this exception
} catch {Exception $e) {        // Actual and effective catch
    // Fix this exception
}
?>

See also PHP Try Catch: Basics & Advanced PHP Exception Handling Tutorial and Silent failure to catch exceptions in PHP.

1.2.1271.1. Suggestions

  • Fix the name of the exception

  • Remove the catch clause

  • Add a use expression with a valid name

  • Create/import the missing exception

1.2.1271.2. Specs

Short name

Classes/UnresolvedCatch

Rulesets

All, Changed Behavior, Dead code

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Features

try-catch

ClearPHP

no-unresolved-catch

Available in

Entreprise Edition, Exakat Cloud