1.2.434. Exception Order¶
When catching exception, the most specialized exceptions must be in the early catch, and the most general exceptions must be in the later catch. Otherwise, the general catches intercept the exception, and the more specialized will not be read.
<?php
class A extends \Exception {}
class B extends A {}
try {
throw new A();
}
catch(A $a1) { }
catch(B $b2 ) {
// Never reached, as previous Catch is catching the early worm
}
?>
1.2.434.1. Connex PHP features¶
1.2.434.1.1. Suggestions¶
Remove one of the catch clause
1.2.434.1.2. Specs¶
Short name |
Exceptions/AlreadyCaught |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |