Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active May 11, 2018 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/ba1a56eb09dddfad786fb583df20c1c1 to your computer and use it in GitHub Desktop.
Save adamcameron/ba1a56eb09dddfad786fb583df20c1c1 to your computer and use it in GitHub Desktop.
class C {
function f(){
try {
$someObj->someMethod();
catch (SomeException $e) { // PHPStorm now indicates that there's no reason to handle SomeException cos the try block doesn't throw it
// handle it
}
}
}
class SomeClass {
function someMethod(){
if ($someCondition) {
return "good value";
}
throw new SomeException("bad result");
}
}
@artspb
Copy link

artspb commented Mar 6, 2018

Here's the proper code, it works just fine.

<?php
class SomeException extends Exception {}
class C {
    function f(SomeClass $someObj){
        try {
            $someObj->someMethod(false);
        }
        catch (SomeException $e) {  // PHPStorm now indicates that there's no reason to handle SomeException cos the try block doesn't throw it
                // handle it
            }
	}
}

class SomeClass {
    function someMethod(bool $someCondition){
        if ($someCondition) {
            return "good value";
        }
        throw new SomeException("bad result");
    }
}

@wshawn
Copy link

wshawn commented May 11, 2018

In my case, PHP storm then reports there is no return on the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment