We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Which exceptions are being caught with beforeException?

So in my actions some functions may throw an exception, so I wanted to handle those in a single place. I thought a beforeException event was exactly what I was looking for. However I could not get it working.

Basically that's what I was doing

$eventsManager = new Phalcon\Events\Manager();
$eventsManager->attach("dispatch", function($event, $dispatcher, $exception) {
    die(var_dump("Got there"));

and then in action for example

public function indexAction() {
    throw new \Exception("test");

However it didn't work. Exceptions thrown in actions were not caught. So, maybe they have to be specific exceptions?

This is working for me:

$eventsManager->attach("dispatch:beforeException", ...


Would you please post more code? It seems like i'm doing exactly the same thing, but it doesn't work. BTW, which Phalcon version are you on? I'm using 1.3.0 latest compilation.