Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throwing Exception from command executed in controller

Tags:

symfony

I am working with Symfony 2, and I am trying to make a small problem solver bundle.

I have the entity Problem that contains a retry field, containing information on which command to execute to retry what failed before.

So here is the code of my controller:

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);
}

When my command fails, it normally throws an exception. However here, the Exception thrown during the command just seems to stop the command, but the execution of my controller continues.

How could I know in my controller if the command ended good or bad?

like image 262
Hammerbot Avatar asked Sep 15 '25 07:09

Hammerbot


1 Answers

I'm sorry, I found the solution in the Application class that contains a setCatchExceptions() method. The solution is the one below:

$application = new Application($kernel);
$application->setCatchExceptions(false);
like image 171
Hammerbot Avatar answered Sep 17 '25 21:09

Hammerbot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!