【发布时间】:2012-05-24 10:13:32
【问题描述】:
我正在尝试抛出异常,我正在执行以下操作:
use Symfony\Component\HttpKernel\Exception\HttpNotFoundException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
然后我以下列方式使用它们:
throw new HttpNotFoundException("Page not found");
throw $this->createNotFoundException('The product does not exist');
但是我遇到了诸如 HttpNotFoundException is not found 之类的错误。
这是抛出异常的最佳方式吗?
【问题讨论】:
-
抛出它们作为你的第一个例子是正常的, throw new Exception('Message');只要您像使用 use 语句那样导入了异常类,它就应该可以工作。可能还有更多您没有展示的内容 - 您可以发布您的实际类头和异常堆栈跟踪吗?
-
我得到的错误是:致命错误:在 /Users/jinni/Sites/symfony.com/src/Rest/UserBundle/Controller/DefaultController 中找不到类“Rest\UserBundle\Controller\HttpNotFoundException”。 php
-
我在顶部包含了 use Symfony\Component\HttpKernel\Exception