Catching database exceptions in Symfony2

前端 未结 2 1122
野趣味
野趣味 2021-01-07 11:45

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 e

2条回答
  •  一向
    一向 (楼主)
    2021-01-07 12:14

    Define a service like this:

    
                
                
    
    

    And a class like this:

    use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
    
    class KernelExceptionListener
    {
        private $logger;
    
        public function __construct(Monolog\Logger $logger)
        {
            $this->logger = $logger;
        }
    
        public function onKernelException(GetResponseForExceptionEvent $event)
        {
            // Here check the exception
            //$event->getException()
        }
    }
    

提交回复
热议问题