Check the fields definition array and throw an exception if it does not make sense.
e.g. if we encounter negative values for 'from' or 'to' or if they are missing.

@throws \RuntimeException
166484
protected function checkFieldsDefinition()
    {
        if (count($this->fields) === 0) {
            throw new \RuntimeException("fields definition is empty");
        }
        foreach ($this->fields as $i => $field) {
            if (!isset($field['from'])) {
                throw new \RuntimeException("'from' is missing for field '$i'");
            }
            if (!isset($field['to'])) {
                throw new \RuntimeException("'to' is missing for field '$i'");
            }
            if (!is_integer($field['from'])) {
                throw new \RuntimeException("'from' is not an integer (field '$i')");
            }
            if (!is_integer($field['to'])) {
                throw new \RuntimeException("'to' is not an integer (field '$i')");
            }
            if ($field['from']<0) {
                throw new \RuntimeException("'from' is negative (field '$i')");
            }
            if ($field['to']<0) {
                throw new \RuntimeException("'to' is negative (field '$i')");
            }
            if ($field['from']>$field['to']) {
                throw new \RuntimeException("'from' not less than to (field '$i')");
            }
        }
    }
785084
public function validationApplies()
    {
        $return = true;

        if ($criteria = $this->owner->validationLogicCriteria) {
            $fields = $this->owner->rootFieldList();
            if (eval($criteria->phpEvalString()) === false) {
                throw new Exception("There is a syntax error in the constaint logic phpEvalString \"{$criteria->phpEvalString()}\"");
            }
            $return = eval('return ' . $criteria->phpEvalString());
        }

        return $return;
    }
416415
public function isValid()
    {
        $value = $this->field->getValue();

        if (is_array($value) || is_object($value)) {
            throw new \Exception("This validator only works on scalar types!");
        }

        // required but not given.
        if ($this->required && strval($value) === "") {
            return false;
        } // if the field is not required and the value is empty, then it's also valid
        elseif (!$this->required && strval($value) === '') {
            return true;
        }

        // check if the field contains a valid number value.
        if (!preg_match($this->getRegex(), $value)) {
            return false;
        }

        // check if the value is not to low.
        if ($this->isValueTooLow($value)) {
            return false;
        }

        // check if the value is not to high.
        if ($this->isValueTooHigh($value)) {
            return false;
        }

        return true;
    }
1311378
protected function validateFilePath()
    {
        if (file_exists($this->filePath)) {
            if (!is_writable($this->filePath)) {
                throw new RuntimeException(
                    "File '{$this->filePath}' exist but is not writable"
                );
            }
        } else {
            if (!is_writable(dirname($this->filePath))) {
                throw new RuntimeException(
                    "File '{$this->filePath}' is not writable"
                );
            }
        }
    }
426181
protected function Neg()
	{
	    throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::UnaryOperatorNotDefined,
			array(
				"fn:unary-minus",
				SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One )
			)
		);
	}
1248577
public function parse()
    {
        if (!is_string($this->data)) {
            throw new \RuntimeException('The given data is no valid string');
        }
        libxml_use_internal_errors(true);
        $xml = simplexml_load_string($this->data);
        if ($xml === false) {
            throw new \RuntimeException('Error during the loading of the XML file');
        }
        if (!isset($xml->executables, $xml->excludes)) {
            throw new \RuntimeException('Missing configuration elements');
        }

        foreach ($xml->excludes->children()->file as $file) {
            $this->config->addExcludedFile((string) $file);
        }

        foreach ($xml->excludes->children()->dir as $dir) {
            $this->config->addExcludedDir((string) $dir);
        }

        foreach ($xml->executables->children() as $file) {
            $this->config->addExecutableFile((string) $file);
        }

        return $this->config;
    }
357302
public function isValid()
    {
        $value = $this->field->getValue();

        if (is_array($value) || is_object($value)) {
            throw new \Exception("This validator only works on scalar types!");
        }

        // required but not given
        if ($this->required && $value == null) {
            return false;
        } // if the field is not required and the value is empty, then it's also valid
        elseif (!$this->required && $value == "") {
            return true;
        }

        $match = preg_match($this->regex, $value);

        return $this->not ? !$match : $match;
    }
155538
public function isFillable($column)
    {
        $guarded = $this->config('guarded', []);

        if (! is_array($guarded)) {
            throw new \RuntimeException('Config field [guarded] must be an array of attributes to protect from mass assignment.');
        }

        $protected = [
            $this->getCreatedAtField(),
            $this->getUpdatedAtField(),
            $this->getDeletedAtField(),
        ];

        if ($this->primaryKeys->columns) {
            $protected = array_merge($protected, $this->primaryKeys->columns);
        }

        foreach (array_merge($guarded, $protected) as $pattern) {
            if (Str::is($pattern, $column)) {
                return false;
            }
        }

        return true;
    }
408570
public function toArray()
    {
        $data = array();

        foreach ($this as $key => $value) {
            if (is_object($value)) {
                if (!is_callable(array($value, 'toArray'))) {
                    throw new RuntimeException('Object does not implement toArray() method on key: ' . $key);
                }
                $data[$key] = $value->toArray();
            } else {
                $data[$key] = $value;
            }
        }

        return $data;
    }
9944
public function run()
    {
        if (!isset($this->conditions)
            || !isset($this->callable)
        ) {

            $message = "You have called the run function but have not provided both a array of conditions";
            $message .= " and a callable function, which will be called if all the given conditions are met.";

            throw new \RuntimeException($message);
        }

        $this->conditions->rewind();
        while ($this->conditions->valid()) {

            $condition = $this->conditions->current();

            if (!call_user_func($condition)) {
                return false;
            }

            $this->conditions->next();
        }

        call_user_func($this->callable, $this->request);
        return true;

    }
677450
private function validate()
    {
        if (!class_exists($this->class)) {
            throw new \RuntimeException(sprintf('Class %s does not exist, is this the correct namespace?', $this->class));
        }
        if (!in_array($this->method, get_class_methods($this->class))) {
            throw new \RuntimeException(sprintf('The method "%s" does not exist in "%s" class.', $this->method, $this->class));
        }
    }
36809
protected function validate_data() {
        parent::validate_data();
        // Make sure this class is never used without proper object details.
        if (empty($this->objectid) || empty($this->objecttable)) {
            throw new \coding_exception('The course_module_viewed event must define objectid and object table.');
        }
        // Make sure the context level is set to module.
        if ($this->contextlevel != CONTEXT_MODULE) {
            throw new \coding_exception('Context level must be CONTEXT_MODULE.');
        }
    }
902911
private function decodeDict()
    {
        $dict = array();
        $terminated = false;
        $dictOffset = $this->offset;

        while (false !== $this->getChar()) {
            if ("e" == $this->getChar()) {
                $terminated = true;
                break;
            }

            $keyOffset = $this->offset;
            if (!ctype_digit($this->getChar())) {
                throw new RuntimeException("Invalid dictionary key at offset $keyOffset");
            }

            $key = $this->decodeString();
            if (isset ($dict[$key])) {
                throw new RuntimeException("Duplicate dictionary key at offset $keyOffset");
            }

            $dict[$key] = $this->doDecode();
        }

        if (!$terminated && false === $this->getChar()) {
            throw new RuntimeException("Unterminated dictionary definition at offset $dictOffset");
        }

        $this->offset++;

        return $dict;
    }
891376
public function checkDataIsEmpty()
    {
        if ($this->isDataExists() === false) {
            $this->contextDataEmpty = true;
        }
        elseif (is_object($this->getDataValue())) {
            $this->contextDataEmpty = false;
        }
        elseif (is_array($this->getDataValue())) {
            $this->contextDataEmpty = false;
        }
        elseif (is_string($this->getDataValue())) {
            $this->contextDataEmpty = (bool) (strlen($this->getDataValue()) == 0);
        }
        elseif (is_numeric($this->getDataValue())) {
            $this->contextDataEmpty = false;
        }
        else {
            $this->contextDataEmpty = (bool) $this->checkIsEmpty($this->getDataValue());
        }
    }
192085
protected function validate_data() {
        if ($this->other === null) {
            throw new \coding_exception('The \'competencyid\' and \'planid\' values must be set.');
        }

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

        if (!isset($this->other['planid'])) {
            throw new \coding_exception('The \'planid\' value must be set.');
        }
    }
124779
final public function valuesHadChanged(): bool
    {
        if (! is_array($this->originalValues)) {
            throw new \RuntimeException('The recordset does not contain any original values');
        }
        foreach ($this->originalValues as $field => $value) {
            $current = array_key_exists($field, $this->values) ? $this->values[$field] : null;
            if ($this->valueIsDifferent($value, $current)) {
                return true;
            }
        }
        return false;
    }
1215911
protected function loadValueOptions()
    {
        $om = $this->objectManager;
        if (!$om) {
            throw new RuntimeException('No object manager was set');
        }
    
        if (!($targetClass = $this->targetClass)) {
            throw new RuntimeException('No target class was set');
        }
    
        $metadata   = $om->getClassMetadata($targetClass);
        $identifier = $metadata->getIdentifierFieldNames();
        $objects    = $this->getObjects();
        $options    = array();
    
        if (empty($objects)) {
            $options[''] = '';
        } else {
            foreach ($objects as $key => $object) {
                if (($property = $this->property)) {
                    if ($this->isMethod == false && !$metadata->hasField($property)) {
                        throw new RuntimeException(sprintf(
                            'Property "%s" could not be found in object "%s"',
                            $property,
                            $targetClass
                        ));
                    }
    
                    $getter = 'get' . ucfirst($property);
                    if (!is_callable(array($object, $getter))) {
                        throw new RuntimeException(sprintf(
                            'Method "%s::%s" is not callable',
                            $this->targetClass,
                            $getter
                        ));
                    }
    
                    $label = $object->{$getter}();
                } else {
                    if (!is_callable(array($object, '__toString'))) {
                        throw new RuntimeException(sprintf(
                            '%s must have a "__toString()" method defined if you have not set a property or method to use.',
                            $targetClass
                        ));
                    }
    
                    $label = (string) $object;
                }
    
                if (count($identifier) > 1) {
                    $value = $key;
                } else {
                    $value = current($metadata->getIdentifierValues($object));
                }
    
                $options[] = array('label' => $label, 'value' => $value);
            }
        }
    
        $this->valueOptions = $options;
    }