1.2.1296. Unused Exception Variable¶
The variable from a catch clause is not used. It is expected to be used, either by chaining the exception, or logging the message.
In PHP 8.0, this variable may be omitted.
<?php
try{
doSomething();
} catch (A $a) {
// $a is caught, but not used here
} catch (B $b) {
// $b is caught, and used
log($b->getMessage());
} catch (C) {
// Caught and ignored (PHP 8.0 +)
}
?>
1.2.1296.1. Connex PHP features¶
1.2.1296.1.1. Suggestions¶
Drop the variable in the clause expression (PHP 8.0 and more recent)
Chain the exception
Log the exception message
1.2.1296.1.2. Specs¶
Short name |
Exceptions/UnusedExceptionVariable |
Rulesets |
|
Exakat since |
2.2.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |