2016-09-22 87 views
2

我正在与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似乎停止了命令,但我的控制器的执行仍在继续。

我怎么能在我的控制器中知道命令结束了好还是坏?

+0

目前,我唯一的解决方案是在'输出'查找'[Exception]'字符串,但它的感觉是如此,这么糟糕的做法... – Hammerbot

回答

1

对不起,我在Application类中找到了包含setCatchExceptions()方法的解决方案。解决方案如下:

$application = new Application($kernel); 
$application->setCatchExceptions(false); 
+0

你有没有看到[ConsoleEvents :: EXCEPTION](https://symfony.com/doc/current/components/console/events.html#the-consoleevents-exception-event) – doydoy44

+0

不,我没有看到,非常感谢您的分享! – Hammerbot

+0

不客气。你应该验证你的答案:) – doydoy44

相关问题