B
B
BonBon Slick2018-04-30 02:39:57
phpstorm
BonBon Slick, 2018-04-30 02:39:57

Hint bug in IDE?

/** 
     * @throws UserNotFoundException 
     */
    private function obtain()  
    {
        try {
           // do stuff 
        }
        catch (UserNotFoundException | Exception $throwable) {
           //do stuff
        }
    }

Exception 'UserNotFoundException' is never thrown in the function less...
The inspection reports @throws tags which don't have corresponding exceptions thrown by function
Technically these are not errors but practically usually indicate programmer's mistakes.
That is, it gives 2 hints, saying that the action was never thrown and makes it gray + yellow underlined by phpdoc, although it was thrown.
If you remove the Exception catch, it will throw another hint that
Unhandled \Exception less... (
The inspection reports exceptions which are neither enclosed in a try-catch block nor documented using the '@throws' tag
If you make the code inspection level 2 out of 3 , these hints will disappear.How
to fix this?Should I create a ticket on the PhPStorm forum?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gradysden, 2019-11-17
@Gradysden

This is not a bug, phpstorm requires the "@throws" tag to be written in the place where the exception is thrown, not handled, generally logical.
function editFile($fileName,$path){
try{
......your code...
openFile($fileName, $path);
}catch(Exception $exception){
...catch body....
}
function openFile($file,$path){
....some code....
throw new Exception( 'error');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question