1.2.1280. 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.1280.1. Connex PHP features¶
1.2.1280.1.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.1280.1.2. Specs¶
Short name |
Classes/UnresolvedCatch |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
High |
ClearPHP |
|
Available in |