Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dmag's avatar
Level 6

Stop reporting propagation from exception class

The default reporting behavior is defined in the report method of App\Exceptions\Handler class, however I'd like my custom exception class to use a different reporting behavior, defined its report method. However, it still propagates to the default reporting of the Handler class. I've tried returning true and false - no difference.

class MyException extends \Exception
{
    public function report()
    {
        // custom reporting logic
        
        return true; // return false;
    }
}
0 likes
9 replies
dmag's avatar
Level 6

@martinbean the handler has the reporting logic, but I want one particular exception to have a different reporting logic.

martinbean's avatar

@dmag Different reporting logic how? Tell us the problem; not the attempted solution.

dmag's avatar
Level 6

@martinbean i don't want that particular exception be reported to Sentry, which is the default reporting behavior defined in exception handler. I want it to be reported to another place.

martinbean's avatar

@dmag Reporting behaviour are not defined in the exception handler. Laravel uses log channels to specify where errors are recorded.

Why would you set up Sentry for error reporting, but then not want to send exceptions to Sentry? What’s special about this particular exception, and where do you want to report it?

dmag's avatar
Level 6

@martinbean sorry, but your questions are irrelevant to my issue. If there's no way to stop propagation from inside the exception class, then okay. There's a way to stop propagation from inside the handler by appending stop(), but it's inside handler class, which is not what I want.

martinbean's avatar

@dmag I’m just trying to understand your use case in order to suggest the most appropriate solution. They’re not “irrelevant” when I’m asking about questions specifically about your problem.

Usually when you find something difficult, it’s because you’re doing it wrong and fighting something rather than using the appropriate solution.

dmag's avatar
Level 6

@martinbean thank you, but if there's no way to stop propagation fron inside exception class, then I will have to do it from inside the handler class, which would not be my choice otherwise.

martinbean's avatar

@dmag Or you could just answer what’s special about the class, and why you want to log it somewhere other than Sentry, and then maybe someone can suggest the most appropriate solution for your problem?

Please or to participate in this conversation.