How to Catch exception in the controller and show flash message in Symfony 2?
try{
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('target page'));
} catch(\Exception $e){
// What to do in this part???
}
return $this->render('MyTestBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
What should I do in the catch block?
echo (string)$e;or better, send you an email on a productive site:mail('[email protected]', 'Exception in script ...', var_export($e, true));