diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 74de1048bb172..63bafb1fd9fd5 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -116,8 +116,15 @@ public function run(InputInterface $input = null, OutputInterface $output = null $this->configureIO($input, $output); try { + $e = null; $exitCode = $this->doRun($input, $output); - } catch (\Exception $e) { + } catch (\Exception $x) { + $e = $x; + } catch (\Throwable $x) { + $e = new FatalThrowableError($x); + } + + if (null !== $e) { if (!$this->catchExceptions) { throw $e; } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 2612be9e9eaaa..056f0d26e0990 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -969,6 +969,24 @@ public function testRunWithError() $tester->run(array('command' => 'dym')); } + public function testRunWithErrorCatchExceptionsFailingStatusCode() + { + $application = new Application(); + $application->setDispatcher(new EventDispatcher()); + $application->setCatchExceptions(true); + $application->setAutoExit(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')); + $this->assertSame(1, $tester->getStatusCode(), 'Status code should be 1'); + } + /** * @expectedException \LogicException * @expectedExceptionMessage caught