I am trying to catch a custom exception, but keep getting an Exception 'CustomException' is never thrown in the corresponding try block
inspection error for the following scenario:
class CustomException extends Exception { }
class Test {
/**
* @throws CustomException
*/
public function willFail()
{
throw new CustomException('I failed');
}
}
$test = new Test;
try {
$test->willFail();
} catch (CustomException $e) {
echo $e->getMessage();
}
The above example works exactly as expected, aside from PhpStorm giving me the inspection error.
I've searched everywhere and can't find out how to fix this without disabling the inspection entirely. Any help would be greatly appreciated!