symfony2和抛出异常错误 [英] symfony2 and throwing exception error
本文介绍了symfony2和抛出异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Symfony\Component\HttpKernel\ Exception\HttpNotFoundException;
使用Symfony\Component\Security\Core\Exception\AccessDeniedException;
然后我以下列方式使用它们:
抛出新的HttpNotFoundException(找不到页面);
throw $ this-> createNotFoundException('该产品不存在');
但是我收到错误,如HttpNotFoundException没有找到。
这是抛出异常的最佳方法?
解决方案
尝试:
使用Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
和
抛出新的NotFoundHttpException(找不到页面);
我想你有点向后: - )
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 :-)
这篇关于symfony2和抛出异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文