diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 8875e03e8442..e056862b8e67 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -544,15 +544,16 @@ public function handleException($exception, array $error = null) } } } + $exceptionHandler = $this->exceptionHandler; + $this->exceptionHandler = null; try { - if (null !== $this->exceptionHandler) { - return \call_user_func($this->exceptionHandler, $exception); + if (null !== $exceptionHandler) { + return \call_user_func($exceptionHandler, $exception); } $handlerException = $handlerException ?: $exception; } catch (\Exception $handlerException) { } catch (\Throwable $handlerException) { } - $this->exceptionHandler = null; if ($exception === $handlerException) { self::$reservedMemory = null; // Disable the fatal error handler throw $exception; // Give back $exception to the native handler diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index f2d0fc8b0bc8..18834badae21 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -530,4 +530,17 @@ public function testLegacyInterface() throw $e; } } + + /** + * @expectedException \Exception + */ + public function testCustomExceptionHandler() + { + $handler = new ErrorHandler(); + $handler->setExceptionHandler(function ($e) use ($handler) { + $handler->handleException($e); + }); + + $handler->handleException(new \Exception()); + } }