diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index 82ffa95d7120..1fed81e7a78b 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -229,7 +229,11 @@ private function handleException(\Exception $e, $request, $type) if (!$event->hasResponse()) { $this->finishRequest($request, $type); - throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e); + if ($this->dispatcher->hasListeners(KernelEvents::EXCEPTION)) { + throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e); + } + + throw $e; } $response = $event->getResponse(); diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php index 0b110d4a21b2..83182e63eae5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php @@ -102,8 +102,8 @@ public function testHandleRestoresThePreviousRequestOnException($type) $this->fail('->handle() suppresses the controller exception'); } catch (\PHPUnit_Framework_Exception $exception) { throw $exception; - } catch (\LogicException $actual) { - $this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener'); + } catch (\Exception $actual) { + $this->assertSame($expected, $actual, '->handle() throws the controller exception'); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 8f93f913f480..b793cf0f9e7e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -23,17 +23,14 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase { + /** + * @expectedException \RuntimeException + */ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() { - $exception = new \RuntimeException(); - $kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; })); + $kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); })); - try { - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); - $this->fail('LogicException expected'); - } catch (\LogicException $e) { - $this->assertSame($exception, $e->getPrevious()); - } + $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); } /**