diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b11268ade33b..2aff1b635ba1 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -843,7 +843,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI } if (null === $this->dispatcher) { - return $command->run($input, $output); + try { + return $command->run($input, $output); + } catch (\Exception $e) { + throw $e; + } catch (\Throwable $e) { + throw new FatalThrowableError($e); + } } $event = new ConsoleCommandEvent($command, $input, $output); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 9d375f6b7b26..2612be9e9eaa 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -951,6 +951,24 @@ public function testRunDispatchesAllEventsWithException() $this->assertContains('before.foo.caught.after.', $tester->getDisplay()); } + public function testRunWithError() + { + $this->setExpectedException('Exception', 'dymerr'); + + $application = new Application(); + $application->setAutoExit(false); + $application->setCatchExceptions(false); + + $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + $output->write('dym.'); + + throw new \Error('dymerr'); + }); + + $tester = new ApplicationTester($application); + $tester->run(array('command' => 'dym')); + } + /** * @expectedException \LogicException * @expectedExceptionMessage caught