2013-03-12 2 views
0

Symfony2 컨트롤러에서 예외가 발생했습니다 ... NotFoundHttpException을 잡으려고하는데 catch 블록이 ... 일어나지 않습니다. ... 대신 개발 환경에서 스택 추적과 함께 표준 Symfony2 예외 페이지로 이동 Symfony2 - 컨트롤러에서 catch 블록을 실행하지 않습니다.

나는 다음과 같은 코드가 있습니다

<?php 

namespace SeerUK\DWright\GalleryBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Response; 

use SeerUK\DWright\GalleryBundle\Entity\Gallery; 


class GalleryController extends Controller 
{ 
    public function indexAction($galleryId) 
    { 
     try 
     { 
      $gallery = $this->getDoctrine() 
       ->getRepository('SeerUKDWrightGalleryBundle:Gallery') 
       ->find($galleryId); 

      throw $this->createNotFoundException('rawr'); // Just for the sake of testing... 

      if (!$gallery) { 
       throw $this->createNotFoundException(
        'No gallery found for id ' . $galleryId 
       ); 
      } 

      $galleryId   = $gallery->getId(); 
      $galleryName  = $gallery->getName(); 
      $galleryDesc  = $gallery->getDesc(); 
      $galleryPublishedOn = $gallery->getPublishedOn(); 

      return $this->render('SeerUKDWrightGalleryBundle:Gallery:index.html.twig', array(
       'galleryId'   => $galleryId, 
       'galleryName'  => $galleryName, 
       'galleryDesc'  => $galleryDesc, 
       'galleryPublishedOn' => $galleryPublishedOn->format('Y-m-d H:i:s'), 
      )); 
     } 
     catch (Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) 
     { 
      echo $e->message; 
     } 
    } 
} 

답변

1

당신은 catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)을 시도하거나이 NotFoundHttpException를 사용해야을 ...

아마 당신의 경우에는 SeerUK\DWright\GalleryBundle\Controller\Symfony\Component\HttpKernel\Exception\NotFoundHttpException를 잡으려고합니다.

+0

당신은 정확합니다! Symfony2 예외 이름 앞에'\'가 필요했습니다. :) – Seer

관련 문제