I am trying to catch exceptions inside an Action in a Controller in Symfony2.3 application during entity persistance.
try {
$em->persist($firm);
} catch(\Exception $e){
.........
}
I expected that all errors will be handled by my code inside catch statement, instead I got following errors:
[2/2] DBALException: An exception occurred while executing 'INSERT INTO ...
...
[1/2] PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
...
CRITICAL - Uncaught PHP Exception Doctrine\DBAL\DBALException
If I throw exception inside try statement it is cought and handled properly by code inside catch
try {
throw new \Doctrine\ORM\ORMException;
//or throw new \Doctrine\DBAL\DBALException;
//or throw new \PDOException;
} catch(\Exception $e){
.......
}
My question is: How one should properly handle Doctrine2 inside Symfony2 controller. Thanks.