I've got a random problem that I can't narrow down. Occasionally, I will get the following error in a Symfony2 application:
Uncaught Exception: An exception occured in driver: SQLSTATE[08004] [1040] Too many connections {"type":1,"file":"/var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php","line":115,"level":30709
I would like to setup an application-wide listener to catch the PDOException
and log some information. How can I hook into Symfony to only catch PDOException
?
You need to create custom exception listener. It will listen to all exceptions, but you will specify type check inside it.
In your
services.yml
you need to specify listener:Now you need to create this class:
YourExceptionListener:
Check doc how to create event listener
Define a service like this:
And a class like this: