Check required options
If a required option is not provided then throw and exception

@throws \Exception if required param or option is not present
322995
private function checkRequired()
    {
        // Loop through all params
        foreach ($this->params as $param) {
            if (array_key_exists('required', $param) && $param['required'] == true) {
                if (!array_key_exists($param['name'], $this->pinputs)) {
                    throw new \Exception('Parameter "' . $param['name'] . '" is required');
                }
            }
        }

        // Loop through all options
        foreach ($this->options as $key => $option) {
            // if option is required
            if (array_key_exists('required', $option) && $option['required'] == true) {
                // check that it is defined in pinputs
                if ($this->pinputs[$option['short']] == false) {
                    throw new \Exception('Option "' . $option['help'] . '" is required');
                }
            }
        }

    }
1253243
protected function validate_data() {
        parent::validate_data();

        if (!isset($this->relateduserid)) {
            debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
            $this->relateduserid = $this->objectid;
        }

        if (!isset($this->other['username'])) {
            throw new \coding_exception('The \'username\' value must be set in other.');
        }

        if (!isset($this->other['email'])) {
            throw new \coding_exception('The \'email\' value must be set in other.');
        }

        if (!isset($this->other['idnumber'])) {
            throw new \coding_exception('The \'idnumber\' value must be set in other.');
        }

        if (!isset($this->other['picture'])) {
            throw new \coding_exception('The \'picture\' value must be set in other.');
        }

        if (!isset($this->other['mnethostid'])) {
            throw new \coding_exception('The \'mnethostid\' value must be set in other.');
        }
    }
1275562
private void validateOptions() {
        // No validation if we found a help parameter
        if (helpWasSpecified) {
            return;
        }

        if (!requiredFields.isEmpty()) {
            List<String> missingFields = new ArrayList<>();
            for (ParameterDescription pd : requiredFields.values()) {
                missingFields.add("[" + Strings.join(" | ", pd.getParameter().names()) + "]");
            }
            String message = Strings.join(", ", missingFields);
            throw new ParameterException("The following "
                    + pluralize(requiredFields.size(), "option is required: ", "options are required: ")
                    + message);
        }

        if (mainParameter != null && mainParameter.description != null) {
            ParameterDescription mainParameterDescription = mainParameter.description;
            // Make sure we have a main parameter if it was required
            if (mainParameterDescription.getParameter().required() &&
                    !mainParameterDescription.isAssigned()) {
                throw new ParameterException("Main parameters are required (\""
                        + mainParameterDescription.getDescription() + "\")");
            }

            // If the main parameter has an arity, make sure the correct number of parameters was passed
            int arity = mainParameterDescription.getParameter().arity();
            if (arity != Parameter.DEFAULT_ARITY) {
                Object value = mainParameterDescription.getParameterized().get(mainParameter.object);
                if (List.class.isAssignableFrom(value.getClass())) {
                    int size = ((List<?>) value).size();
                    if (size != arity) {
                        throw new ParameterException("There should be exactly " + arity + " main parameters but "
                                + size + " were found");
                    }
                }

            }
        }
    }
939130
protected function _validateConfig()
    {
        foreach ($this->_config as $key => $value) {
            if (!isset($value)) {
                throw new \Exception('Incomplete configuration: ' . $key, 1);
            }
        }
    }
1342436
public static void checkRequired(OptionSet options, String opt) throws VoldemortException {
        List<String> opts = Lists.newArrayList();
        opts.add(opt);
        checkRequired(options, opts);
    }
510935
public static void checkForRemainingOptions(String[] options) 
    throws Exception {
    
    int illegalOptionsFound = 0;
    StringBuffer text = new StringBuffer();

    if (options == null) {
      return;
    }
    for (int i = 0; i < options.length; i++) {
      if (options[i].length() > 0) {
	illegalOptionsFound++;
	text.append(options[i] + ' ');
      }
    }
    if (illegalOptionsFound > 0) {
      throw new Exception("Illegal options: " + text);
    }
  }
259798
protected function validate()
    {
        /** @var Parameter[] $missingItems */
        $missingItems = \array_filter($this->_options + $this->_arguments, function ($item) {
            /* @var Parameter $item */
            return $item->required() && \in_array($this->_values[$item->attributeName()], [null, []]);
        });

        foreach ($missingItems as $item) {
            list($name, $label) = [$item->name(), 'Argument'];
            if ($item instanceof Option) {
                list($name, $label) = [$item->long(), 'Option'];
            }

            throw new RuntimeException(
                \sprintf('%s "%s" is required', $label, $name)
            );
        }
    }
900591
protected function requiresOptions()
    {
        $url = $this->getEndPointUrl();
        $variables = $this->extractUrlVariables($url);
        return !empty($variables);
    }
821476
protected function checkRequirements($mode)
    {
        if (true !== in_array($mode, self::$validModes, true)) {
            throw new Exception(
                sprintf('Mode "%s" not supported. Supported: "%s"', $mode, var_export(self::$validModes, true))
            );
        }

        switch ($mode) {
            case self::MODE_OPEN_SSL:
            case self::MODE_PHP_DEFAULT:
            case self::MODE_PHP_MERSENNE_TWISTER:
            default:
                // Intentionally omitted cause not required - listed here for code quality and readability
                break;
        }

        return true;
    }
276294
protected function validateArgs()
    {
        $message = null;
        foreach ($this->getMandatoryArgs() as $arg) {
            if (!isset($this->args[$arg])) {
                $message = "Argument $arg was not present in supplied job args for job " . get_class($this);
                $this->errorLog($message);
                throw new \Exception($message);
            }
        }
        if ($this->configRequired) {
            $this->ensureConfig();
        }
    }
721525
private function validate_config($config)
    {
        $required_option_keys = array('access_token', 'environment');

        foreach ($required_option_keys as $required_option_key) {
            if (!isset($config[$required_option_key])) {
                throw new \Exception('Missing required option `' . $required_option_key . '`.');
            }

            if (!is_string($config[$required_option_key])) {
                throw new \Exception('Option `'. $required_option_key .'` can only be a string.');
            }
        }
    }
1118151
def require(self, fieldname, allow_blank=False):
        """"""
        if self.request.form and fieldname not in self.request.form.keys():
            raise Exception("Required field not found in request: %s" % fieldname)
        if self.request.form and (not self.request.form[fieldname] or allow_blank):
            raise Exception("Required field %s may not have blank value")
1095669
private function prepareOptions()
    {
        $metadata = $this->metadata();

        // Can be override from the outside.
        if (!$this->exportIdent()) {
            $exportIdent = $this->exportIdent() ? : $this->metadata()->get('admin.default_export');
            if (!$exportIdent) {
                throw new Exception(sprintf(
                    'No export ident defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }

            $this->setExportIdent($exportIdent);
        }

        $export = $metadata->get('admin.export.'.$this->exportIdent());
        if (!$export) {
            throw new Exception(sprintf(
                'No export data defined for "%s" at "%s" in %s',
                $this->objType(),
                $this->exportIdent(),
                get_class($this)
            ));
        }

        if (is_string($export)) {
            $export = $metadata->get('admin.lists.'.$export);
            if (!$export) {
                throw new Exception(sprintf(
                    'No export data defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }
        }

        if (!isset($export['properties'])) {
            throw new Exception(sprintf(
                'No properties defined to export "%s" in %s',
                $this->objType(),
                get_class($this)
            ));
        }

        if (isset($export['exporter_options'])) {
            $opts = $export['exporter_options'];
            if (isset($opts['convert_br_to_newlines'])) {
                $this->setConvertBrToNewlines($opts['convert_br_to_newlines']);
            }
            if (isset($opts['strip_tags'])) {
                $this->setStripTags($opts['strip_tags']);
            }
            if (isset($opts['filename'])) {
                $this->setFilename($opts['filename']);
            }
        }

        // Default filename.
        // Filename is not a requirement
        if (!$this->filename()) {
            $ts = new DateTime('now');
            $filename = str_replace('/', '.', strtolower($this->objType())).'-export-'.$ts->format('Ymd.His').'.csv';
            $this->setFilename($filename);
        }

        // Properties to be exported
        // They will defined the file header and the rows.
        $this->setProperties($export['properties']);

        // Unnecessary for collection config.
        unset($export['properties']);
        unset($export['exporter_options']);

        // The rest is just collection config
        $this->setCollectionConfig($export);

        return $this;
    }
209678
protected function init($options)
    {
        foreach ($options as $parameterName => $parameterValue) {
            if ( ! isset ($this->{$parameterName})) {
                throw new \Exception ("The parameter $parameterName is not a valid parameter name");
            }

            if (gettype($this->{$parameterName}) != gettype($parameterValue)) {
                throw new \Exception ("The parameter value type passed for $parameterName is not an accepted type, only " . gettype($this->{$parameterName}));
            }

            $this->{'set' . ucfirst($parameterName)}($parameterValue);
        }
    }
1327315
public static void checkRequired(OptionSet options, List<String> opts)
            throws VoldemortException {
        List<String> optCopy = Lists.newArrayList();
        for(String opt: opts) {
            if(options.has(opt)) {
                optCopy.add(opt);
            }
        }
        if(optCopy.size() < 1) {
            System.err.println("Please specify one of the following options:");
            for(String opt: opts) {
                System.err.println("--" + opt);
            }
            Utils.croak("Missing required option.");
        }
        if(optCopy.size() > 1) {
            System.err.println("Conflicting options:");
            for(String opt: optCopy) {
                System.err.println("--" + opt);
            }
            Utils.croak("Conflicting options detected.");
        }
    }
587075
private function handleUndefinedParameters()
    {
        $leftover = count($this->rawParams);

        if (0 < $leftover) {
            if (1 == $leftover) {
                $msg = 'The parameter \'%s\' is not valid';
            } else {
                $msg = 'The parameters \'%s\' are not valid';
            }

            throw new \Exception(sprintf($msg, implode('\', \'', array_keys($this->rawParams))));
        }
    }
55401
private function throwRequired(array $args)
    {
        $missing = [];
        foreach ($this->argDefinitions as $k => $a) {
            if (empty($a['required'])
                || isset($a['default'])
                || isset($args[$k])
            ) {
                continue;
            }
            $missing[] = $this->getArgMessage($k, $args, true);
        }
        $msg = "Missing required client configuration options: \n\n";
        $msg .= implode("\n\n", $missing);
        throw new IAE($msg);
    }