Return Page not Found (404) or Access Denied (403) page

To throw a 404 error:

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
// then
throw new NotFoundHttpException();

To throw a 403 error:

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
// then
throw new AccessDeniedHttpException();