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?
Try:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;   and
throw new NotFoundHttpException("Page not found");   I think you got it a bit backwards :-)
If its in a controller, you can do it this way :
throw $this->createNotFoundException('Unable to find entity.'); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With