{@inheritdoc}

@throws Exception\MethodNotImplemented if any enabled state implement the required method
@throws \Throwable

@see http://php.net/manual/en/class.iterator.php
509311
public function seek($position): void
    {
        $args = [$position];
        $methodName = __FUNCTION__;

        $this->findAndCall($methodName, $args);
    }
945758
protected function error(\Throwable $exception)
    {
        if ($this->errorHandler === null) {
            throw $exception;
        }

        ($this->errorHandler)($exception);
    }
282018
public function add()
    {
        if (!$this->request->is(['get', 'post'])) {
            throw new MethodNotAllowedException();
        }

        /** @var User $user */
        $user = $this->Users->newEntity(null, ['associated' => 'Groups']);

        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data, ['associated' => 'Groups']);
            $user->set('password', Text::uuid());

            if ($this->Users->save($user, ['associated' => 'Groups'])) {
                $this->Users->Tokens->invalidateExistingTokens($user->id, TokensTable::TYPE_EMAIL_VERIFICATION);
                $token = $this->Users->Tokens->generateToken($user, TokensTable::TYPE_EMAIL_VERIFICATION);
                $this->getMailer('Wasabi/Core.User')->send('verifyAndResetPasswordEmail', [$user, $token]);
                $this->Flash->success(__d('pb', 'The user <strong>{0}</strong> has been created.', $user->fullName()));
                $this->redirect(['action' => 'index']);
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }

        $groups = $this->Users->Groups->find('list')->order('id ASC');

        // users that are no admin, may not select the super admin group
        if (Wasabi::user()->hasAccessLevel(Permission::OWN)) {
            $groups->where(['id <>' => 1]);
        }

        $this->set([
            'user' => $user,
            'groups' => $groups,
            'languages' => Hash::map(Configure::read('languages.backend'), '{n}', function ($language) {
                return [
                    'value' => $language->id,
                    'text' => $language->name
                ];
            })
        ]);
    }
13113
public function andRun()
    {
        if ($this->_returns) {
            throw new Exception("Some return value(s) has already been set.");
        }
        $closures = func_get_args();
        foreach ($closures as $closure) {
            if (!is_callable($closure)) {
                throw new Exception("The passed parameter is not callable.");
            }
        }
        $this->_closures = $closures;
    }
653941
public function afterExecuteRoute() {
        /** @var \Bullhorn\FastRest\Api\Services\Output\OutputInterface $output */
        $output = $this->getDI()->get(OutputInterface::DI_NAME);
        if(!($output instanceof OutputInterface)) {
            throw new \Exception('The Output must implement: ' . OutputInterface::class);
        }
        $object = $this->getOutputObject();
        $errors = $this->getErrors();
        $code = $this->getStatusCode();

        $object = $this->addErrorsAndStatus($errors, $code, $object);
        $this->response->setStatusCode($object->statusCode, 'Check Document Body For More Details');
        $output->output($object, $this->response);
        $this->view->disable();
    }
714997
public function delete()
    {
        if (!$this->isXmlHttpRequest()) {
            throw new \Exception("wrong request mode");
        }

        $deleted = $this->getClassService()->deleteInstance($this->getCurrentInstance());

        $this->returnJson(array(
            'deleted' => $deleted
        ));
    }
1281166
protected function sendResponse(Response $response, Throwable $exception): void
	{
		if($exception instanceof MethodNotAllowedException)
		{
			$this->response->getHeaders()->add('Allow', implode(',', $exception->getAllowedMethods()));
		}

		$response->send();
	}
250413
public function run()
    {
        try {

            // ~ Hook for console help
            if (! $this->argument->has('name')) {

                // ~ Display Help
                $this->help();

                // ~ If no help asked, throw exception !
                if (! $this->argument->has('help')) {
                    throw new \Exception(__METHOD__ . '|Script name must be defined !');
                }

                return;
            }

            // ~ Create new object '*'
            $className = $this->argument->get('name');
            $script = new $className();

            if (!($script instanceof ConsoleInterface)) {
                throw new \Exception('Current script must be implement ConsoleInterface interface !');
            }

            if (! $script->executable()) {
                throw new \Exception(__METHOD__ . '|Script is not executable !');
            }

            $style = new Style(' >>> RUN - ' . $className . ' - ' . date('Y-m-d H:i:s') . ' <<<');
            $style->color('fg', Style::COLOR_GREEN);

            if ($this->argument->has('help')) {

                Out::std($style->get());

                $script->help();
            } else {

                // ~ Execute this method before starting main script method
                $script->before();

                // ~ Display header script only after execution of before method (prevent error with start_session() for example).
                Out::std($style->get());

                // ~ Execute main script method.
                $script->run();

                // ~ Execute this method after execution of main script method.
                $script->after();
            }
        } catch (\Exception $exception) {

            if (! $this->isVerbose) {
                throw $exception;
            }

            $style = new Style(' ~~ EXCEPTION[' . $exception->getCode() . ']: ' . $exception->getMessage());
            $style->color('bg', Style::COLOR_RED);
            Out::std(PHP_EOL . $style->get());

            if ($this->argument->has('debug')) {
                echo $exception->getTraceAsString(), PHP_EOL;
            }
        }
    }
198310
private function dispatchException(\Throwable $t) {
		array_unshift($this->dispatchingThrowables, $t);
		$numDispatchingThrowables = sizeof($this->dispatchingThrowables);
		
		if (!N2N::isInitialized() || 2 < $numDispatchingThrowables || (2 == $numDispatchingThrowables 
				&& !($this->dispatchingThrowables[1] instanceof StatusException)) || !$this->stable) {
			if (!isset($_SERVER['HTTP_HOST'])) {
				$this->renderExceptionConsoleInfo($t);
				return;
			}
			
			$this->renderFatalExceptionsHtmlInfo($this->dispatchingThrowables);
			return;
		}
		
		if (!N2N::isHttpContextAvailable()) {
			$this->renderExceptionConsoleInfo($t);
			return;
		}

		try {
			$this->renderBeautifulExceptionView($t);
		} catch (\Throwable $t) {
			$this->handleThrowable($t);
		}
	}
1092067
protected static function execute()
    {
        try {
            $instance = static::getInstance();

            $reflectionMethod = new ReflectionMethod($instance, static::$method);

            return $reflectionMethod->invokeArgs($instance, static::$arguments);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
543647
public function execute()
    {
        if (!file_exists($this->location)) {
            mkdir($this->location);
        }
        if (!is_writable($this->location)) {
            throw new \Exception(sprintf('The location %s is not writable or does not exist.', $this->location));
        }

        $pdepend = $this->phpci->findBinary('pdepend');

        $cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';

        $this->removeBuildArtifacts();

        // If we need to ignore directories
        if (count($this->phpci->ignore)) {
            $ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
        } else {
            $ignore = '';
        }

        $success = $this->phpci->executeCommand(
            $cmd,
            $this->location . DIRECTORY_SEPARATOR . $this->summary,
            $this->location . DIRECTORY_SEPARATOR . $this->chart,
            $this->location . DIRECTORY_SEPARATOR . $this->pyramid,
            $ignore,
            $this->directory
        );

        $config = $this->phpci->getSystemConfig('phpci');

        if ($success) {
            $this->phpci->logSuccess(
                sprintf(
                    "Pdepend successful. You can use %s\n, ![Chart](%s \"Pdepend Chart\")\n
                    and ![Pyramid](%s \"Pdepend Pyramid\")\n
                    for inclusion in the readme.md file",
                    $config['url'] . '/build/pdepend/' . $this->summary,
                    $config['url'] . '/build/pdepend/' . $this->chart,
                    $config['url'] . '/build/pdepend/' . $this->pyramid
                )
            );
        }

        return $success;
    }
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);
        }
    }
1317229
function getMethod($methodName)
    {
        if (!$this->hasMethod($methodName))
            throw new \Exception(sprintf(
                'Method (%s) not found.'
                , $methodName
            ));

        if (isset($this->_t__methods[$methodName])) {
            ## from bind closure
            $methodCallable = $this->_t__methods[$methodName];
        } else {
            $bindTo = $this->getBindTo();
            $methodCallable = function() use($methodName, $bindTo) {
                return call_user_func_array([$bindTo, $methodName], func_get_args());
            };
        }

        ## bind it into latest bind object
        $methodCallable = \Closure::bind(
            $methodCallable
            , $this->getBindTo()
            , get_class($this->getBindTo())
        );

        return $methodCallable;
    }
1086382
public function init() {
        if (!$this->database->session_lock_supported()) {
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Database does not support session locking');
        }

        $result = session_set_save_handler(array($this, 'handler_open'),
            array($this, 'handler_close'),
            array($this, 'handler_read'),
            array($this, 'handler_write'),
            array($this, 'handler_destroy'),
            array($this, 'handler_gc'));
        if (!$result) {
            throw new exception('dbsessionhandlerproblem', 'error');
        }
    }
890441
protected function throwsBadMethodCallException(/*# string */ $method)
    {
        throw new Exception\BadMethodCallException(
            Message::get(Message::IMMUTABLE_EVENT_METHOD, $method),
            Message::IMMUTABLE_EVENT_METHOD
        );
    }
330197
public function init()
    {
        if (empty($this->rawFiles)) {
            throw new ErrorException('No file specified; make sure you are using the correct .htaccess rules.');
        }

        // Handle legacy code for minifying
        if (preg_match('%^/minify/%', $this->rawFiles)) {
            $this->rawFiles = substr($this->rawFiles, 7);
            $this->setRawParam('minify', 'true');
        }

        $this->ext = strtolower(pathinfo($this->rawFiles, PATHINFO_EXTENSION));
        $supportedExtensions = Registry::getSupportedExtensions($this->ext);
        // Suppressing errors because Exceptions thrown in the callback cause Warnings.
        $webroot = $this->webroot;
        $this->files = @array_map(function($v) use ($supportedExtensions, $webroot) {
            // Make sure all the file extensions are supported
            if (! in_array(strtolower(pathinfo($v, PATHINFO_EXTENSION)), $supportedExtensions)) {
                throw new ErrorException('All requested files need to be: ' . implode(', ', $supportedExtensions));
            }
            // Strip any parent directory slugs (../) - loop through until they are all gone
            $count = 1;
            while ($count > 0) {
                $v = preg_replace('%(/\\.\\.?|\\.\\.?/)%', '', $v, -1, $count);
                // If there is no slash prefix, add it back in
                if (substr($v, 0, 1) != '/') {
                    $v = '/' . $v;
                }
            }

            // Remove sub-folder if in the path, it shouldn't be there.
            $v = str_replace(SUB_FOLDER, '', $v);

            return $webroot . $v;
        }, explode(',', $this->rawFiles));
    }
54795
public function handle(Throwable $exception) : void
    {
        foreach ($this->handlers as $handler) {
            $result = $handler($exception);

            if ($result instanceof Throwable) {
                $exception = $result;
            }
        }

        throw $exception;
    }