An exception is created and dropped without being thrown

tx0/php:unthrown-exceptiondefaultwarningreliability/error-handlingdepth fastbug

What it finds

new InvalidArgumentException('...'); as a statement creates an exception and drops it: nothing is thrown, and the code goes on as if the check had passed. throw was meant.

From the rule's source, unthrown_exception.rs.

Example from the rule's tests
<?phpfunction check($x){    if ($x < 0) {        new InvalidArgumentException('negative');tx0 reports: a InvalidArgumentException is created but not thrown    }    if ($x > 9) {        throw new \RangeException('too big');    }    new Widget();}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/php:unthrown-exception" = "off"

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:unthrown-exception] reason="..."

tx0 explain tx0/php:unthrown-exception shows the same in the terminal. Found a false positive? Report it.