从控制器中执行的命令抛出异常
问题描述:
我正在与Symfony 2一起工作,并且我正在尝试制作一个小问题求解器包。从控制器中执行的命令抛出异常
我的实体Problem
包含一个retry
字段,其中包含有关要执行哪个命令以重试以前失败的信息的信息。
因此,这里是我的控制器代码:
public function retryAction($id)
{
$em = $this->getDoctrine()->getManager();
$problem = $em->getRepository('RBLogsBundle:Problem')->find($id);
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput($problem->getRetry());
$output = new BufferedOutput();
$application->run($input,$output);
$content = $output->fetch();
return new Response($content);
}
当我的命令失败,它通常会抛出异常。然而,在这里,命令期间抛出的Exception似乎停止了命令,但我的控制器的执行仍在继续。
我怎么能在我的控制器中知道命令结束了好还是坏?
答
对不起,我在Application
类中找到了包含setCatchExceptions()
方法的解决方案。解决方案如下:
$application = new Application($kernel);
$application->setCatchExceptions(false);
目前,我唯一的解决方案是在'输出'查找'[Exception]'字符串,但它的感觉是如此,这么糟糕的做法... – Hammerbot