coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

False positive SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch.NonCapturingCatchRequired

Open Chi-teck opened this issue 2 years ago • 1 comments

Version: slevomat/coding-standard 8.14.1

Code to reproduce:

try {
  // Do something.
}
catch (\Exception $exception) {
  // Intentionally empty.
}
finally {
  \var_dump(isset($exception));
}

Error: Non-capturing catch is required.

The code example looks weird but it is valid. Apparently the corresponding sniff does not check usage of $exception variable outside of catch block.

Chi-teck avatar Dec 09 '23 13:12 Chi-teck

A bit different, but related with the same sniff false positive:

function () {
    do {
        try {

        } catch (\Throwable $e) {

        }
    } while (true);

    throw $e;
};

rmikalkenas avatar Jan 02 '24 12:01 rmikalkenas

Fixed in https://github.com/slevomat/coding-standard/commit/d82a6713c0063ba31e1d2bbc8a6df22798a2e370

kukulich avatar Mar 09 '24 13:03 kukulich