Skip to content

Commit

Permalink
bug #26568 [Debug] Reset previous exception handler earlier to preven…
Browse files Browse the repository at this point in the history
…t infinite loop (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Debug] Reset previous exception handler earlier to prevent infinite loop

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26438
| License       | MIT
| Doc PR        | -

Commits
-------

f7e1bb0 [Debug] Reset previous exception handler ealier to prevent infinite loop
  • Loading branch information
nicolas-grekas committed Mar 19, 2018
2 parents 2fb2ed0 + f7e1bb0 commit 567cbaa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -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());
}
}

0 comments on commit 567cbaa

Please sign in to comment.