Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 and throwing exception error

Tags:

I am trying to throw exceptions and I am doing the following:

use Symfony\Component\HttpKernel\Exception\HttpNotFoundException; use Symfony\Component\Security\Core\Exception\AccessDeniedException; 

I am then using them the following way:

 throw new HttpNotFoundException("Page not found");    throw $this->createNotFoundException('The product does not exist'); 

however I am getting errors like HttpNotFoundException is not found etc.

Is this the best way to throw exceptions?

like image 605
jini Avatar asked May 16 '12 19:05

jini


2 Answers

Try:

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 

and

throw new NotFoundHttpException("Page not found"); 

I think you got it a bit backwards :-)

like image 95
Chris McKinnel Avatar answered Oct 02 '22 13:10

Chris McKinnel


If its in a controller, you can do it this way :

throw $this->createNotFoundException('Unable to find entity.'); 
like image 29
Chopchop Avatar answered Oct 02 '22 12:10

Chopchop