Throw the first exception from the exception stack.

@param array $exceptionStack

@throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException

@return void
767902
protected function throwUnauthorizedException(array $exceptionStack)
    {
        $exception = array_shift($exceptionStack);

        if ($exception === null) {
            $exception = new UnauthorizedHttpException('dingo', 'Failed to authenticate because of bad credentials or an invalid authorization header.');
        }

        throw $exception;
    }
400447
protected function throwExceptionIfFalse()
    {
        $args = func_get_args();

        $condition = array_shift($args);

        if (!$condition) {
            $args = array_map([$this, 'stringify'], $args);

            $message = call_user_func_array('sprintf', $args);

            throw new InvalidArgumentException($message);
        }
    }
954172
public function setJsonCallbackWrap($callback)
    {

        if (empty($callback)) {
            $this->jsonCallbackWrap = false;
            return;
        }

        if (!is_string($callback)) {
            throw new \Exception('JSON callback wrap should be a string or false.');
        }

        $this->jsonCallbackWrap = $callback;
    }
385355
protected function throwError($exception)
    {
        switch ($exception->getResponse()->getStatusCode()) {
            case 400:
                throw new BadRequestException($exception);
                break;

            case 401:
                throw new UnauthorizedException($exception);
                break;

            case 403:
                throw new MethodNotAllowedException($exception);
                break;

            case 404:
                throw new NotFoundException($exception);
                break;

            default:
                throw new Exception($exception);
                break;
        }
    }
712849
public function emulateExceptionOnRemoteLoop()
    {
        if ($this->isExternal()) {
            $this->loop->nextTick(function () {
                $this->emulateException();
            });
        } else {
            $this->callOnChild(__FUNCTION__, func_get_args());
        }
    }
314793
public function onKernelException(GetResponseForExceptionEvent $event): void
    {
        $exception = $event->getException();

        if (!$exception instanceof AccessDeniedException) {
            return;
        }

        $event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
    }
602342
public function init() {
        if (VERBOSE) echo 'INIT:' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING API' ,PHP_EOL;
        $this->api->auth();
        if (VERBOSE) echo ' API CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CONNECTING SQL' ,PHP_EOL;
        $this->db->connect();
        if (VERBOSE) echo ' SQL CONNECTED' ,PHP_EOL;
        if (VERBOSE) echo ' CHECKING PATHS' ,PHP_EOL;
        if (DEBUG) echo '  CHECKING TMP DIR AT : '.$this->tmp_dir ,PHP_EOL;
        if (!file_exists($this->tmp_dir)) {
            throw new Exception("Path for 'tmp_dir' not found at '".$this->tmp_dir."'!");
        }
        if (DEBUG) echo '  CHECKING DUMP DIR AT : '.$this->dumps_dir ,PHP_EOL;
        if (!file_exists($this->dumps_dir)) {
            throw new Exception("Path for 'dumps_dir' not found at '".$this->dumps_dir."'!");
        }
        if (VERBOSE) echo ' PATHS FOUND' ,PHP_EOL;
    }
1035891
public function setAuthnContextDecl(Chunk $authnContextDecl) : void
    {
        if (!empty($this->authnContextDeclRef)) {
            throw new \Exception(
                'AuthnContextDeclRef is already registered! May only have either a Decl or a DeclRef, not both!'
            );
        }

        $this->authnContextDecl = $authnContextDecl;
    }
575926
public static function stop($throw = false)
    {
        $errorException = null;

        if (static::$stack) {
            $errorException = array_pop(static::$stack);

            if (!static::$stack) {
                restore_error_handler();
            }

            if ($errorException && $throw) {
                throw $errorException;
            }
        }

        return $errorException;
    }
728739
public function throwError($msg)
    {
        if ($this->ignoreErrors) {
            return;
        }

        if (func_num_args() > 1) {
            $msg = call_user_func_array('sprintf', func_get_args());
        }

        $line = $this->sourceLine;
        $loc = isset($this->sourceNames[$this->sourceIndex]) ? $this->sourceNames[$this->sourceIndex] . " on line $line" : "line: $line";
        $msg = "$msg: $loc";

        if ($this->callStack) {
            $msg .= "\nCall Stack:\n";
            $ncall = 0;

            foreach (array_reverse($this->callStack) as $call) {
                $msg .= "#" . $ncall++ . " " . $call['n'] . " ";
                $msg .= (isset($this->sourceNames[$call[Parser::SOURCE_INDEX]]) ? $this->sourceNames[$call[Parser::SOURCE_INDEX]] : '(unknown file)');
                $msg .= " on line " . $call[Parser::SOURCE_LINE] . "\n";
            }
        }

        throw new CompilerException($msg);
    }
632570
public function run(HTTPRequest $request) {
		$options = $request->getRoute()->getOptions();
		if( !empty($options['url_config']) ) {
			$url = AppConfig::instance()->get($options['url_config']);
			if( !$url ) {
				throw new Exception('The RedirectController requires a valid url_config option, please check your configuration.');
			}
		} else
		if( empty($options['redirect']) ) {
			throw new Exception('The RedirectController requires a redirect option, add it to your route configuration.');
		} else {
			$url = u($options['redirect']);
		}
		return new RedirectHTTPResponse($url);
	}
362274
private function exception() : void
    {
        if ($this->response->getStatusCode() === Response::HTTP_FORBIDDEN) {
            throw ServiceException::invalidApiKey();
        }

        if ($this->response->getStatusCode() === Response::HTTP_UNPROCESSABLE_ENTITY) {
            throw ServiceException::invalidPayload();
        }

        if ($this->response->getStatusCode() === Response::HTTP_TOO_MANY_REQUESTS) {
            throw ServiceException::rateLimit();
        }

        if ($this->response->getStatusCode() === Response::HTTP_INTERNAL_SERVER_ERROR) {
            throw ServiceException::serverError();
        }

        throw ServiceException::generic();
    }
1347177
protected function _exception($exception, $inEachHook = false)
    {
        if ($exception instanceof SkipException) {
            !$inEachHook ? $this->log()->type('skipped') : $this->_skipChildren($exception);
            return;
        }
        $this->_passed = false;
        $this->log()->type('errored');
        $this->log()->exception($exception);
    }
484518
public function throwException($message = '', $type = 'default')
    {
        switch ($type) {
            case 'access-denied':
                throw new AccessDeniedException($message);
            case 'not-found':
                throw new NotFoundHttpException($message);
            case 'runtime':
                throw new \RuntimeException($message);
            default:
                throw new \Exception($message);
        }
    }
382801
public static function assertInArray($needle, array $haystack)
    {
        if (!in_array($needle, $haystack)) {
            throw new Exception("Unable to find '$needle' in array " . var_export($haystack, true));
        }
    }
1215638
public function pop(){
		if(count($this->stack) > $this->depth) array_pop($this->stack);
		if($this->depth==0) throw new \Exception('Can\' pop nothing');
		$this->depth--;
		
		if($this->current != null){
			$this->current	= $this->current->getParent();
			$this->loaded	= $this->current != null;
		}
	}
1298341
protected function throwJsonException()
    {
        if (JSON_ERROR_NONE === json_last_error()) {
            return;
        }

        switch (json_last_error()) {
            case JSON_ERROR_DEPTH:
                $error = 'The maximum stack depth has been exceeded';
                break;

            case JSON_ERROR_STATE_MISMATCH:
                $error = 'Invalid or malformed JSON';
                break;

            case JSON_ERROR_CTRL_CHAR:
                $error = 'Control character error, possibly incorrectly encoded';
                break;

            case JSON_ERROR_SYNTAX:
                $error = 'Syntax error';
                break;

            case JSON_ERROR_UTF8:
                $error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;

            case JSON_ERROR_RECURSION:
                $error = 'One or more recursive references in the value to be encoded';
                break;

            case JSON_ERROR_INF_OR_NAN:
                $error = 'One or more NAN or INF values in the value to be encoded';
                break;

            case JSON_ERROR_UNSUPPORTED_TYPE:
                $error = 'A value of a type that cannot be encoded was given';
                break;

            default:
                $error = 'Occurred error.';
                break;
        }

        throw new InvalidArgumentException($error);
    }