You are here

public function ExceptionHandler::handle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/debug/ExceptionHandler.php \Symfony\Component\Debug\ExceptionHandler::handle()

Sends a response for the given Exception.

To be as fail-safe as possible, the exception is first handled by our simple exception handler, then by the user exception handler. The latter takes precedence and any output from the former is cancelled, if and only if nothing bad happens in this handling path.

File

vendor/symfony/debug/ExceptionHandler.php, line 115

Class

ExceptionHandler
ExceptionHandler converts an exception to a Response object.

Namespace

Symfony\Component\Debug

Code

public function handle(\Exception $exception) {
  if (null === $this->handler || $exception instanceof OutOfMemoryException) {
    $this
      ->failSafeHandle($exception);
    return;
  }
  $caughtLength = $this->caughtLength = 0;
  ob_start(array(
    $this,
    'catchOutput',
  ));
  $this
    ->failSafeHandle($exception);
  while (null === $this->caughtBuffer && ob_end_flush()) {

    // Empty loop, everything is in the condition
  }
  if (isset($this->caughtBuffer[0])) {
    ob_start(array(
      $this,
      'cleanOutput',
    ));
    echo $this->caughtBuffer;
    $caughtLength = ob_get_length();
  }
  $this->caughtBuffer = null;
  try {
    call_user_func($this->handler, $exception);
    $this->caughtLength = $caughtLength;
  } catch (\Exception $e) {
    if (!$caughtLength) {

      // All handlers failed. Let PHP handle that now.
      throw $exception;
    }
  }
}