A catch block only rethrows what it caught

tx0/php:rethrow-only-catchrecommendedwarningreliability/error-handlingdepth fastsmell

What it finds

catch (Exception $e) { throw $e; }: a catch that only throws the same exception again does nothing but add noise, unless a later catch of the same try would otherwise take the exception, which is then left alone.

From the rule's source, rethrow_only_catch.rs.

Example from the rule's tests
<?phpfunction run(){    try {        work();    } catch (RuntimeException $e) { throw $e; }tx0 reports: this catch only rethrows the exception    try {        work();    } catch (LogicException $e) {        throw $e;    } catch (Exception $e) {        log_it($e);    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/php:rethrow-only-catch" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:rethrow-only-catch] reason="..."

tx0 explain tx0/php:rethrow-only-catch shows the same in the terminal. Found a false positive? Report it.