{@inheritdoc}

@param HttpException|HttpExceptionInterface $e
336685
protected function renderHttpException(HttpExceptionInterface $e)
    {
        $status = $e->getStatusCode();

        if ($this->isCmsWebRequest() &&  view()->exists("cms::errors.{$status}")) {
            $flatException = FlattenException::create($e);

            return response()
                ->view(
                    "cms::errors.{$status}",
                    [ 'exception' => $flatException ],
                    $status,
                    $e->getHeaders()
                );
        }

        return parent::renderHttpException($e);
    }
1183347
public function render($request, Exception $e)
    {
        if ($this->isServiceException($e)) {
            $e->setRequest($request);
        } elseif ($e instanceof ValidationException) {
            $e = $this->convertValidationExceptionToEntityException($e);
        } else {
            $e = $this->convertExceptionToServiceException($e);
        }

        return $this->prepareJsonResponse($e);
    }
1129877
protected function handleViewException($e)
	{
		$e = new \ErrorException($this->getMessage($e), 0, 1, $e->getFile(), $e->getLine(), $e);

		ob_get_clean(); throw $e;
	}
202315
private function handleExternalError(\Exception $e) {
        $reflection = new \ReflectionClass($e);
        echo '<header>';
            echo '<h1>Exception: ' . $reflection->getName() . '</h1>';
            echo '<h2>Message: ' . $e->getMessage() . '</h2>';
            echo '<h3>' . $e->getFile() . ':' . $e->getLine() . '</h3>';
        echo '</header>';
        if ( method_exists($e, 'getContext') ) {
            echo 'Debug:';
            !d( $e->getContext() );
        }
    }
737008
public static function run( \Exception $e )
	{
		$config = config('system.errors');
		if (($config['display'] || is_a( $e, Message::class )) && !($e instanceof QueryException)) {
			$obj = new Response( self::getErrorObject($e), ($e->getCode() ? $e->getCode() : 500) );
		} else {
			$obj = new Response( $e->getMessage(), 500 );
		}
		if ($config['log']) {
			self::logObject($e);
		}
		self::sendResponse( $obj );
	}
1151999
protected function reportException(Exception $e)
    {
        $handler = $this->app->make(ExceptionHandler::class);

        $handler->report($e);
    }
654707
public function _handleException($e)
	{
		if(!$this->_inError && $handler = $this->_application->errorHandler())
		{
			$this->_inError = true;
			$handler->handle($e);
			$this->_inError = false;
		}
		else
		{
			if(php_sapi_name() == 'cli')
			{
				echo $e->__toString();
				exit(1);
			}
			else
			{
				header('HTTP/1.1 500 Internal Server Error');

				echo "<h1>Error: ".$e->getMessage().'</h1>';
				echo '<pre>'.$e->__toString().'</pre>';
				exit(1);
			}
		}
	}
340649
public function handleException($e)
    {
        if (!$e instanceof Exception) { // Since PHP 7, in addition to an Exception, an internal Error may occur.
            // Convert the Error to ErrorException
            $e = new ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); // @codeCoverageIgnore
        } // @codeCoverageIgnore

        $this->getExceptionHandler()->handle($e);
    }
1276555
public function logErrorException(\Exception $e)
    {
        if ($this->getServerContext()->hasLogger(LoggerUtils::SYSTEM)) {
            $this->getServerContext()->getLogger(LoggerUtils::SYSTEM)->error($e->__toString());
        }
    }
504642
public function exceptionHandler($e)
    {
        http_response_code(500);

        $e = $this->runHandlers($e);

        if (!$this->silenceErrors) {
            $formattedResponse = $this->runFormatters($e);
            print $formattedResponse;
        }

        if ($this->silenceErrors &&
            isset($this->errorPage) &&
            !($e instanceof ErrorException)
        ) {
            ob_start();
            $response = $this->errorPage->format($e);
            ob_end_clean();
            print $response;
            return;
        }
    }
924965
public function handle($e)
	{
		$this->logException($e);

		if ($this->isExceptionHalting($e))
		{
			// if headers are sent, we can't send a response
			if(headers_sent())
			{
				echo $this->buildResponseBody($e);
				exit(0);
			}

			// send it off
			$sender = new Http\ResponseSender($this->buildResponse($e));
			$sender->send();

			if (ob_get_level() > 0) ob_flush();
			exit(self::EXIT_CODE);
		}
	}
1152111
protected function prepareResponse($request, Exception $e)
    {
        if (! $this->isHttpException($e) && config('app.debug')) {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        if (! $this->isHttpException($e)) {
            $e = new HttpException(500, $e->getMessage());
        }

        return $this->toIlluminateResponse(
            $this->renderHttpException($e), $e
        );
    }
1002333
protected function handleApiException(ClientException $e, Project $project)
    {
        $response = $e->getResponse();
        if ($response !== null && $response->getStatusCode() === 403) {
            $project->ensureFull();
            $data = $project->getData();
            if (!$project->hasLink('#manage-domains')
                && !empty($data['subscription']['plan'])
                && $data['subscription']['plan'] === 'development') {
                $this->stdErr->writeln('This project is on a Development plan. Upgrade the plan to add domains.');
            }
        } else {
            throw $e;
        }
    }
1037989
public function onKernelException(GetResponseForExceptionEvent $e)
    {
        if (!$this->enabled) return;

        $req = $e->getRequest();
        $cfg = $req->attributes->get('_ac_web_service');

        //notify of generic API error, return early if a response gets set
        $e->getDispatcher()->dispatch(self::API_EXCEPTION, $e);
        if ($e->getResponse()) {
            return;
        }

        //handle exception body format
        $exception = $e->getException();
        $exceptionClass = get_class($exception);

        //preserve specific http exception codes and messages, otherwise it's 500
        $realHttpErrorCode = $outgoingHttpStatusCode = 500;
        $errorMessage = "Internal Server Error";
        if ($exception instanceof ServiceException) {
            $errorData = $exception->getData();
        }
        if ($exception instanceof HttpException) {
            $realHttpErrorCode = $outgoingHttpStatusCode = $exception->getStatusCode();
            $errorMessage = ($exception->getMessage()) ? $exception->getMessage() : Response::$statusTexts[$realHttpErrorCode];
        } elseif (isset($cfg['http_exception_map'][$exceptionClass])) {
            //check exception map for overrides
            $map = $cfg['http_exception_map'];
            $realHttpErrorCode = $outgoingHttpStatusCode = $map[$exceptionClass]['code'];
            $errorMessage =
                (isset($map[$exceptionClass]['message']))
                ? $map[$exceptionClass]['message']
                : Response::$statusTexts[$realHttpErrorCode];
        }

        //set generic error data
        if (!isset ($errorData)) {
            $errorData = [];
        }
        $errorData['response'] = [
            'code' => $realHttpErrorCode,
            'message' => $errorMessage,
        ];

        //inject exception data if configured to do so
        if ($cfg['include_exception_data']) {
            $errorData['exception'] = array(
                'class' => get_class($exception),
                'message' => $exception->getMessage(),
                'code' => $exception->getCode(),
                'file' => $exception->getFile(),
                'line' => $exception->getLine(),
                'trace' => explode("\n", ImprovedStackTrace::getTrace($exception)),
            );
        }

        //serialize error content into requested format, if format is not supported by the serializer, do json
        //TODO: consider support for exception template formats
        $format = isset($cfg['http_response_format']) ? $cfg['http_response_format'] : $cfg['default_response_format'];
        $format = (in_array($format, $this->serializableFormats)) ? $format : 'json';
        $content = $this->container->get('serializer')->serialize($errorData, $format);

        //check for code suppression
        if ($cfg['suppress_response_codes']) {
            $outgoingHttpStatusCode = 200;
        }

        //log the exception
        $logLevel = $realHttpErrorCode >= 500 ? 'error' : 'warning';
        $logMessage =
            "Caught exception (mapped to code $realHttpErrorCode), " .
            "response to client becomes HTTP $outgoingHttpStatusCode $errorMessage\n" .
            ImprovedStackTrace::getTrace($exception) . "\n---";
        $this->logger->log($logLevel, $logMessage);

        $headers = array_merge($cfg['additional_headers'], $this->formatHeaders[$format]);

        //set response
        $e->setResponse(new Response($content, $outgoingHttpStatusCode, $headers));
    }
368779
public function handleException( \Throwable $e ) : bool
    {
        if ( $e instanceof HttpStatusException )
        {
            // Show HTTP error document
            $html = $this->provider->getErrorDocument( $e->getStatusCode() );
            
            // output html
            echo $html;

            return true;
        }

        return false;
    }
1263138
public static function wrapException(RequestInterface $request, \Exception $e)
    {
        if ($e instanceof RequestException) {
            return $e;
        } elseif ($e instanceof ConnectException) {
            return new HttpConnectException($e->getMessage(), $request, null, $e);
        } else {
            return new RequestException($e->getMessage(), $request, null, $e);
        }
    }
581342
public function throwServiceExceptionFromRequestException(RequestException $exception)
    {
        $exceptionClass = ExceptionInterface::class;

        if ($exception->hasResponse() && $exception->getResponse()->hasHeader('X-WS-ErrorCode')) {
            $exceptionClass = $this->getServiceException($exception->getResponse()->getHeaderLine('X-WS-ErrorCode'));
        }
        if ($exceptionClass !== ExceptionInterface::class) {
            throw new $exceptionClass();
        }

        throw new ServerException('Unknown error occurred', 0, $exception);
    }