Hard to trace which Exceptions could be thrown in a try/catch block

I sometimes get some random generic error that I have difficulty tracing (it's not hard-coded, or is dynamically-generated), and when it looks like it's coming from a catch block, I'm unable to tell where exactly it's coming from without running `$e->getTraceAsString`, which may not be clear enough.

Is there some way in PHPStorm to view possible Exceptions that could be run in the catch block, without having to run code? I was hoping hovering over something would show (including custom-made ones), but I'm not seeing how that would work.

Comment actions Permalink

I don't think we have such a feature. This is what you are talking about, right?


class MyException1 extends Exception {}
class MyException2 extends Exception {}

class A {
    /** @throws Exception */
    public function m1() {
        if (rand(0, 1)) throw new MyException1();

    /** @throws MyException2 */
    public function m2() {
        throw new MyException2();

try {
    (new A())->m1();
} catch (Exception $e) {
    print $e->getCode(); // Here, on $e, you expect to see MyException1 and MyException2 listed?
Comment actions Permalink

I think that's close but maybe it's more complex... often in code I look at, in a try block, even in function calls not in try blocks, there are Exceptions coded into deeper code, and rather than me trying to dig around and find all of the coded Exceptions that the block could throw, I'd like to hover or click on something to see a list of them.

Comment actions Permalink

Thanks! I've submitted it as WI-66698.


Please sign in to leave a comment.