Try to parse the given value into a Carbon instance, throw if it does not work.

@param  mixed  $value
@param  string  $exceptionClass
@return \Carbon\Carbon

@throws \GraphQL\Error\InvariantViolation|\GraphQL\Error\Error
428526
protected function tryParsingDateTime($value, string $exceptionClass): Carbon
    {
        try {
            return Carbon::createFromFormat(Carbon::DEFAULT_TO_STRING_FORMAT, $value);
        } catch (Exception $e) {
            throw new $exceptionClass(
                Utils::printSafeJson(
                    $e->getMessage()
                )
            );
        }
    }
1237610
public function extract($value)
    {
        if (is_string($value)) {
            return new MongoId($value);
        }
        
        if ($this->nullable && $value === null) {
            return null;
        }
        
        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be a string containing a valid mongo ID, "%s" given.',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
960223
public static function fromValueForClass($value, string $class)
    {
        $message = sprintf(
            'Failed to validate value of type %1$s to fit into Value object of type %2$s. (%3$s)',
            is_object($value) ? get_class($value) : gettype($value),
            $class,
            json_encode($value)
        );

        return new static($message);
    }
390452
public static function async($value, $throw = null)
    {
        if (!self::$self) {
            throw new \BadMethodCallException('Co::async() must be called along with Co::wait(). ');
        }
        if ($throw !== null) {
            $throw = filter_var($throw, FILTER_VALIDATE_BOOLEAN, [
                'flags' => FILTER_NULL_ON_FAILURE,
            ]);
            if ($throw === null) {
                throw new \InvalidArgumentException("\$throw must be null or boolean.");
            }
        }
        self::$self->start($value, false, $throw);
    }
1276189
public function validateValueType($value)
    {
        if ($this->hasOption(Entity\Reflection\Property\Option\Primary::KEY)
            && (Entity\Reflection\Property\Option\Primary::isEmpty($value))
        ) {
            throw new Exception\InvalidArgumentException(
                "Primary value can not be empty string or null!",
                $value
            );
        }

        if ($value === null) {
            return;
        }

        // Enumeration
        if ($this->hasOption(Entity\Reflection\Property\Option\Enum::KEY)
            && !$this->getOption(Entity\Reflection\Property\Option\Enum::KEY)->isValid($value)
        ) {
            throw new Exception\InvalidArgumentException(
                "Value " . $value . " is not from defined entity enumeration "
                . "range on property " . $this->name . "!",
                $value
            );
        }

        // Scalar or array type
        if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {

            if (gettype($value) === $this->type) {
                return;
            }
            throw new Exception\InvalidArgumentException(
                "Expected " . $this->type . " but " . gettype($value)
                . " given on property " . $this->name . "!",
                $value
            );
        }

        // Object validation
        $givenType = gettype($value);
        if ($givenType === "object") {
            $givenType = get_class($value);
        }

        if ($this->type === self::TYPE_ENTITY) {
            // Entity

            $expectedEntityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if ($value instanceof $expectedEntityClass) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected entity " . $this->typeOption . " but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_COLLECTION) {
            // Collection

            $entityClass = Convention::nameToClass($this->typeOption, Convention::ENTITY_MASK);
            if (!$value instanceof Entity\Collection) {

                throw new Exception\InvalidArgumentException(
                    "Expected entity collection but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            } elseif ($value->getEntityClass() !== $entityClass) {
                throw new Exception\InvalidArgumentException(
                    "Expected collection of entity " . $entityClass
                    . " but collection of entity " . $value->getEntityClass()
                    . " given on property " . $this->name . "!",
                    $value
                );
            } else {
                return;
            }
        } elseif ($this->type === self::TYPE_DATETIME) {
            // DateTime

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected DateTime but " . $givenType . " given on"
                    . " property " . $this->name . "!",
                    $value
                );
            }
        } elseif ($this->type === self::TYPE_DATE) {
            // Date

            if ($value instanceof \DateTime) {
                return;
            } else {
                throw new Exception\InvalidArgumentException(
                    "Expected date as DateTime object but " . $givenType
                    . " given on property " . $this->name . "!",
                    $value
                );
            }
        } else {
            // Unexpected

            throw new \Exception("Unsupported type " . $this->type . "!");
        }
    }
37636
public function setValue($value) {
		if (is_array($value)) {
		    foreach ($value as $singleValue) {
		        if (!$this->isValueValid($singleValue)) {
		            throw new \Exception('Unexpected value type');
		        }
		    }
		} elseif (!$this->isValueValid($value)) {
		    throw new \Exception('Unexpected value type');
		}
		$this->value = $value;

		return $this;
	}
415537
public function wrap($value = null)
    {
        $exceptionFactory   = new ExceptionFactory($this->presenter);
        $wrappedObject      = new WrappedObject($value, $this->presenter);
        $caller             = new Caller($wrappedObject, $this->example, $this->dispatcher, $exceptionFactory, $this);
        $arrayAccess        = new SubjectWithArrayAccess($caller, $this->presenter, $this->dispatcher);
        $expectationFactory = new ExpectationFactory($this->example, $this->dispatcher, $this->matchers);

        return new Subject(
            $value, $this, $wrappedObject, $caller, $arrayAccess, $expectationFactory
        );
    }
11346
protected function modelToNorm($value)
    {
        try {
            /* @var DataTransformerInterface $transformer */
            foreach ($this->config->getModelTransformers() as $transformer) {
                $value = $transformer->transform($value);
            }
        } catch (TransformationFailedException $exception) {
            throw new TransformationFailedException(
                'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
                $exception->getCode(),
                $exception
            );
        }

        return $value;
    }
996337
private function filter(&$value)
    {
        if (isset($this->patterns[$value])) {
            $value = $this->patterns[$value];
        } else {
            // Test that pattern is a valid REGEXP pattern
            ErrorHandler::start();
            $this->pattern = (string) $value;
            $status        = preg_match($this->pattern, "Test");
            $error         = ErrorHandler::stop();
        
            if (false === $status) {
                throw new Exception\InvalidArgumentException("Internal error parsing the pattern '{$this->value}'", 0, $error);
            }
        }
    }
1283129
public static function get($value): self
    {
        $class = get_called_class();

        if ($value instanceof self) {
            $value = $value->value();
        }

        if (!static::has($value)) {
            throw EnumException::invalidEnumValue($class, $value);
        }

        return static::all()[$value];
    }
1045076
public function setValue($value)
    {
        if ($this->value !== null && $value !== null) {
            //throw new Exception\BadMethodCallException("Can't set value for static form element");
        }

        return parent::setValue($value);
    }
8807
protected function query($value)
    {
        $filters[$this->getKey()] = $value;
        $result = false;
//         if(!$this->getMapper()->enableFilters($filters))
//             throw new \Exception('Invalid filters used in record validator');
        
        $result = $this->getMapper()->findByFilters($filters);
        return $result;
    }
143553
public function setValue($value)
    {
        if (is_scalar($value)) {
            $this->value = new StringValue($value);
        } elseif (is_array($value)) {
            $this->value = new ArrayValue($value);
        } else {
            if (!$value instanceof ValueInterface) {
                throw new \Exception('The value must implement the ValueInterface.');
            } else {
                $this->value = $value;
            }
        }

        return $this;
    }
583794
public function replace($name, $value) {
        if (!isset($this->unresolvedDeps[$name])) {
            throw new Exception("Dependency does not exist: $name!");
        }
        if (isset($this->resolvedDeps[$name])) {
            throw new Exception("Could replace resolved Dependency: $name!");
        }
        $this->unresolvedDeps[$name] = &$value;
    }
627678
protected function toObject($value, $exclude, $public = false)
  {
    switch (gettype($value))
    {
      case ConversionEnum::OBJECT_CONVERSION:
        if ($public === false)
        {
          return $value;
        }

        return $this->objectToPublicObject($value, $exclude);
        break;
      case ConversionEnum::ARRAY_CONVERSION:
        return $this->arrayToObject($value, $exclude);
        break;
      case ConversionEnum::STRING_CONVERSION:
        return (json_decode($value) === null ? $this->fail($value, 'object') : json_decode($value));
        break;
    }

    return $this->fail($value, 'object');
  }
330790
public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if (empty($value)) {
            return null;
        }

        if ($value instanceof UuidInterface) {
            return $value;
        }

        try {
            return $this->decode($value);
        } catch (InvalidArgumentException $e) {
            throw ConversionException::conversionFailed($value, self::NAME);
        }
    }
678479
public function filter($value, $options = [])
    {
        if ($this->getPattern() == null) {
            $ex = new \Exception(get_class($this) . ' does not have a valid MatchPattern set.');
            throw $ex;
        }

        return preg_replace($this->getPattern(), $this->getReplacement(), $value);
    }