src/RepositoryTrait.php
public function findOneByOrFail(array $criteria)
    {
        $object = $this->findOneBy($criteria);

        if ($object === null) {
            throw new FindException('FindOneBy did not return any results');
        }

        return $object;
    }
public function findOneByOrFail(array $criteria)
    {
        $object = $this->findOneBy($criteria);

        if ($object === null) {
            throw new FindException('FindOneBy did not return any results');
        }

        return $object;
    }
Find elements or throw an exception if none found.

@param array $criteria

@throws FindException

@return object