You are here

public function ErrorHandler::handleException in Zircon Profile 8

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

Handles an exception by logging then forwarding it to another handler.

@internal

Parameters

\Exception|\Throwable $exception An exception to handle:

array $error An array as returned by error_get_last():

File

vendor/symfony/debug/ErrorHandler.php, line 455

Class

ErrorHandler
A generic ErrorHandler for the PHP engine.

Namespace

Symfony\Component\Debug

Code

public function handleException($exception, array $error = null) {
  if (!$exception instanceof \Exception) {
    $exception = new FatalThrowableError($exception);
  }
  $type = $exception instanceof FatalErrorException ? $exception
    ->getSeverity() : E_ERROR;
  if ($this->loggedErrors & $type) {
    $e = array(
      'type' => $type,
      'file' => $exception
        ->getFile(),
      'line' => $exception
        ->getLine(),
      'level' => error_reporting(),
      'stack' => $exception
        ->getTrace(),
    );
    if ($exception instanceof FatalErrorException) {
      if ($exception instanceof FatalThrowableError) {
        $error = array(
          'type' => $type,
          'message' => $message = $exception
            ->getMessage(),
          'file' => $e['file'],
          'line' => $e['line'],
        );
      }
      else {
        $message = 'Fatal ' . $exception
          ->getMessage();
      }
    }
    elseif ($exception instanceof \ErrorException) {
      $message = 'Uncaught ' . $exception
        ->getMessage();
      if ($exception instanceof ContextErrorException) {
        $e['context'] = $exception
          ->getContext();
      }
    }
    else {
      $message = 'Uncaught Exception: ' . $exception
        ->getMessage();
    }
    if ($this->loggedErrors & $e['type']) {
      $this->loggers[$e['type']][0]
        ->log($this->loggers[$e['type']][1], $message, $e);
    }
  }
  if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
    foreach ($this
      ->getFatalErrorHandlers() as $handler) {
      if ($e = $handler
        ->handleError($error, $exception)) {
        $exception = $e;
        break;
      }
    }
  }
  if (empty($this->exceptionHandler)) {
    throw $exception;

    // Give back $exception to the native handler
  }
  try {
    call_user_func($this->exceptionHandler, $exception);
  } catch (\Exception $handlerException) {
  } catch (\Throwable $handlerException) {
  }
  if (isset($handlerException)) {
    $this->exceptionHandler = null;
    $this
      ->handleException($handlerException);
  }
}