Throw an exception for a cURL multi response

@param int $code Curl response code
@throws AdapterException
190188
public static function throwMultiError($code)
    {
        $buffer = function_exists('curl_multi_strerror')
            ? curl_multi_strerror($code)
            : self::ERROR_STR;

        throw new AdapterException(sprintf('cURL error %s: %s', $code, $buffer));
    }
848015
public function setResponseCode($code)
    {
        if (!ResponseCode::isValid($code)) {
            throw new \InvalidArgumentException('setResponseCode(): Invalid HTTP response code given of value ' . strval($code));
        }

        $this->statusCode = $code;
        return $this;
    }
476609
public static function create(int $code = 500, array $context = [], Throwable $previous = null): self
    {
        if (!isset(self::$phrases[$code])) {
            throw new RuntimeException("Http error not valid ({$code})");
        }

        $exception = new static(self::$phrases[$code], $code, $previous);
        $exception->setContext($context);

        return $exception;
    }
1029473
public function httpError($code)
    {
        switch ($code)
        {
            case 400:
                throw new Eresus_HTTP_Exception_BadRequest;
            case 401:
                throw new Eresus_HTTP_Exception_Unauthorized;
            case 402:
                throw new Eresus_HTTP_Exception_PaymentRequired;
            case 403:
                throw new Eresus_HTTP_Exception_Forbidden;
            case 404:
                throw new Eresus_HTTP_Exception_NotFound;
            default:
                throw new Eresus_HTTP_Exception('', $code);
        }
    }
1080536
public static function getMessageFromCode($code)
    {
        if (!array_key_exists($code, self::$responseCodes)) {
            throw new \Exception('The header code '.$code.' is not valid.');
        }

        return self::$responseCodes[$code];
    }
1373995
public function getExceptionByCode($code)
    {
        $code       = (int) $code;
        $exceptions = array();
        foreach ($this->_exceptions as $e) {
            if ($code == $e->getCode()) {
                $exceptions[] = $e;
            }
        }

        if (empty($exceptions)) {
            $exceptions = false;
        }

        return $exceptions;
    }
1092337
private function _throwDispatchException( $message, $exception_code = 0 )
    {
        $exception = new \Exception( $message, $exception_code );

		if ( is_object($this->_events_manager) )
        {
            /**
             * If the event returns false -> exit and don't throw exception
             */
            if ( $this->_events_manager->fire( "dispatch:beforeException", $this, array("exception" => $exception) ) == false )
            {
                return false;
            }
		}

        throw $exception;
    }
997963
public function code($code = false)
    {

        if (!$code) {
            return http_response_code();
        }

        if (headers_sent()) {
            if (self::$exceptOnHeaders && (http_response_code() != $code)) {
                throw new \Exception('Headers already sent. HTTP response code cannot be changed.');
            } else {
                return;
            }
        }

        self::$code = $code;
        http_response_code(self::$code);
    }
1269166
protected function error($code, lang_string $message) {
        if (array_key_exists($code, $this->errors)) {
            throw new coding_exception('Error code already defined');
        }
        $this->errors[$code] = $message;
    }
52888
protected function Crash($errmsg = "Unknown Error", $code = 0, $exception = null)
	{
		$ex = $exception ? $exception : new Exception($errmsg, $code);
		throw $ex;
	}
942788
public function newException(string $code, $value): Exception
    {
        $exception = $this->getException($code);

        return new $exception(
            strtoupper(Str::kebab($this->getManager()->getName())),
            strtoupper(Str::kebab($this->getName())),
            $value
        );
    }
88936
protected function handleHttpError($code)
    {
        try {
            $template = new Template('Error/' . $code, (defined('OCTO_ADMIN') && OCTO_ADMIN ? 'admin' : null));
            $template->set('page', ['title' => 'Error ' . $code . ' - ' . Response::$codes[$code]]);
            $content = $template->render();

            $this->response->setResponseCode($code);
            $this->response->setContent($content);
        } catch (\Exception $ex) {}

        return $this->response;
    }
96036
public function execute($code, $throwExceptions = false)
    {
        $this->setCode($code, true);
        $closure = new ExecutionClosure($this);

        if ($throwExceptions) {
            return $closure->execute();
        }

        try {
            return $closure->execute();
        } catch (\TypeError $_e) {
            $this->writeException(TypeErrorException::fromTypeError($_e));
        } catch (\Error $_e) {
            $this->writeException(ErrorException::fromError($_e));
        } catch (\Exception $_e) {
            $this->writeException($_e);
        }
    }
616564
public function setHttpResponseCode($code)
        {
            if (!is_int($code) || (100 > $code) || (599 < $code)) {
                throw new Exception('Invalid HTTP response code');
            }

            if ((300 <= $code) && (307 >= $code)) {
                $this->_isRedirect = true;
            } else {
                $this->_isRedirect = false;
            }

            $this->_httpResponseCode = $code;

            return $this;
        }
1181215
protected function handleException(\Exception $exception, $httpCode)
    {
        $isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']);

        if ($isAjax) {
            $sEngine = Response\Factory::ENGINE_API;
            $sFormat = Response\Factory::FORMAT_JSON;
            $content = json_encode($exception->getTraceAsString());
        } else {
            $sEngine = Response\Factory::ENGINE_NONE;
            $sFormat = Response\Factory::FORMAT_HTML;
            $content = '<b>Exception[' . $exception->getCode() . ']: ' . $exception->getMessage() . '</b>
            <pre>' . $exception->getTraceAsString() . '</pre>';
        }

        $response = Response\Factory::create($sFormat, $sEngine);
        $response->setHttpCode($httpCode)
            ->setContent($content)
            ->send();
    }
1316187
public function getException($code)
    {
        if (!isset($this->exceptions[$code])) {
            throw new Exceptions\ExceptionNotDefinedException($this, $code);
        }

        return $this->exceptions[$code];
    }
305915
private function createErrorResponse(int $code, Socket $socket): \Generator
    {
        try {
            yield from $this->log->log(
                Log::NOTICE,
                'Error reading request from %s:%d (Status Code: %d)',
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $code
            );

            $response = $this->handler->onError($code, $socket);

            if ($response instanceof \Generator) {
                $response = yield from $response;
            } elseif ($response instanceof Awaitable) {
                $response = yield $response;
            }

            if (!$response instanceof Response) {
                throw new InvalidResultError(sprintf(
                    'A %s object was not returned from %::onError().',
                    Response::class,
                    get_class($this->handler)
                ), $response);
            }
        } catch (Throwable $exception) {
            yield from $this->log->log(
                Log::ERROR,
                "Uncaught exception when creating response to an error from %s:%d on %s:%d in file %s on line %d: %s",
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $socket->getLocalAddress(),
                $socket->getLocalPort(),
                $exception->getFile(),
                $exception->getLine(),
                $exception->getMessage()
            );
            $response = yield from $this->createDefaultErrorResponse(500);
        }

        return $response;
    }