function ErrorHandler::handleException
Handles an exception by logging then forwarding it to another handler.
@internal
File
-
vendor/
symfony/ error-handler/ ErrorHandler.php, line 494
Class
- ErrorHandler
- A generic ErrorHandler for the PHP engine.
Namespace
Symfony\Component\ErrorHandlerCode
public function handleException(\Throwable $exception) : void {
$handlerException = null;
if (!$exception instanceof FatalError) {
self::$exitCode = 255;
$type = ThrowableUtils::getSeverity($exception);
}
else {
$type = $exception->getError()['type'];
}
if ($this->loggedErrors & $type) {
if (str_contains($message = $exception->getMessage(), "@anonymous\x00")) {
$message = $this->parseAnonymousClass($message);
}
if ($exception instanceof FatalError) {
$message = 'Fatal ' . $message;
}
elseif ($exception instanceof \Error) {
$message = 'Uncaught Error: ' . $message;
}
elseif ($exception instanceof \ErrorException) {
$message = 'Uncaught ' . $message;
}
else {
$message = 'Uncaught Exception: ' . $message;
}
try {
$this->loggers[$type][0]
->log($this->loggers[$type][1], $message, [
'exception' => $exception,
]);
} catch (\Throwable $handlerException) {
}
}
$exception = $this->enhanceError($exception);
$exceptionHandler = $this->exceptionHandler;
$this->exceptionHandler = [
$this,
'renderException',
];
if (null === $exceptionHandler || $exceptionHandler === $this->exceptionHandler) {
$this->exceptionHandler = null;
}
try {
if (null !== $exceptionHandler) {
$exceptionHandler($exception);
return;
}
$handlerException ??= $exception;
} catch (\Throwable $handlerException) {
}
if ($exception === $handlerException && null === $this->exceptionHandler) {
self::$reservedMemory = null;
// Disable the fatal error handler
throw $exception;
// Give back $exception to the native handler
}
$loggedErrors = $this->loggedErrors;
if ($exception === $handlerException) {
$this->loggedErrors &= ~$type;
}
try {
$this->handleException($handlerException);
} finally {
$this->loggedErrors = $loggedErrors;
}
}