Code review comment: Shall we add tests for error throwing if not already covered

Code under review:
public static BString toExpString(double x, Object fractionDigits) {
        
        BString str = FloatUtils.getBStringIfInfiniteOrNaN(x);
        if (str != null) {
            return str;
        }

        long noOfFractionDigits;

        
        double xAbsValue = Math.abs(x);
        if (fractionDigits == null) {
            if (xAbsValue == 0) {
                noOfFractionDigits = 1;
            } else {
                int integerPart = (int) (Math.log10(xAbsValue));
                noOfFractionDigits = BigDecimal.valueOf(xAbsValue / Math.pow(10, integerPart)).scale();
            }
        } else {
            noOfFractionDigits = (long) fractionDigits;
        }

        
        if (noOfFractionDigits < 0) {
            throw ErrorUtils.createInvalidFractionDigitsError();
        }

        
        if (FloatUtils.checkFractionDigitsWithinRange(noOfFractionDigits)) {
            
            noOfFractionDigits = 308;
        }

        int exponent = (int) noOfFractionDigits;

        int tens = 0;
        if (xAbsValue != 0 && xAbsValue < 1) {
            double multipliedValue = xAbsValue;

            while (multipliedValue < 1) {
                multipliedValue = xAbsValue * Math.pow(10, tens + 1);
                tens++;
            }
        }

        BigDecimal numberBigDecimal = new BigDecimal(x);
        if (xAbsValue != 0 && xAbsValue < 1) {
            numberBigDecimal  = numberBigDecimal.setScale(exponent + tens, RoundingMode.HALF_EVEN);
        } else {
            numberBigDecimal  = numberBigDecimal.setScale(exponent, RoundingMode.HALF_EVEN);
        }

        String power = "0".repeat(exponent);

        DecimalFormat decimalFormat = new DecimalFormat("0." + power + "E0");
        decimalFormat.setRoundingMode(RoundingMode.HALF_EVEN);
        String res = decimalFormat.format(numberBigDecimal);
        int indexOfExp = res.lastIndexOf("E");
        String firstSection = res.substring(0, indexOfExp);
        int idxOfDecimalPoint = firstSection.lastIndexOf(".");
        if (idxOfDecimalPoint == firstSection.length() - 1) {
            firstSection = res.substring(0, idxOfDecimalPoint);
        }
        String secondSection = res.substring(indexOfExp + 1);
        int p = Integer.parseInt(secondSection);
        if (p >= 0) {
            secondSection = "e+" + secondSection;
        } else {
            secondSection = "e" + secondSection;
        }

        return StringUtils.fromString(firstSection + secondSection);
    }

Line commented on: throw ErrorUtils.createInvalidFractionDigitsError();

Revised code:
public static BString toExpString(double x, Object fractionDigits) {
        
        BString str = FloatUtils.getBStringIfInfiniteOrNaN(x);
        if (str != null) {
            return str;
        }

        long noOfFractionDigits;

        
        double xAbsValue = Math.abs(x);
        if (fractionDigits == null) {
            if (xAbsValue == 0) {
                noOfFractionDigits = 1;
            } else {
                int integerPart = (int) (Math.log10(xAbsValue));
                noOfFractionDigits = BigDecimal.valueOf(xAbsValue / Math.pow(10, integerPart)).scale();
            }
        } else {
            noOfFractionDigits = (long) fractionDigits;
        }

        
        if (noOfFractionDigits < 0) {
            throw ErrorUtils.createInvalidFractionDigitsError();
        }

        
        if (FloatUtils.checkFractionDigitsWithinRange(noOfFractionDigits)) {
            
            noOfFractionDigits = 308;
        }

        int exponent = (int) noOfFractionDigits;

        int tens = 0;
        if (xAbsValue != 0 && xAbsValue < 1) {
            double multipliedValue = xAbsValue;

            while (multipliedValue < 1) {
                multipliedValue = xAbsValue * Math.pow(10, tens + 1);
                tens++;
            }
        }

        BigDecimal numberBigDecimal = new BigDecimal(x);
        if (xAbsValue != 0 && xAbsValue < 1) {
            numberBigDecimal  = numberBigDecimal.setScale(exponent + tens, RoundingMode.HALF_EVEN);
        } else {
            numberBigDecimal  = numberBigDecimal.setScale(exponent, RoundingMode.HALF_EVEN);
        }

        String power = "0".repeat(exponent);

        DecimalFormat decimalFormat = new DecimalFormat("0." + power + "E0");
        decimalFormat.setRoundingMode(RoundingMode.HALF_EVEN);
        String res = decimalFormat.format(numberBigDecimal);
        int indexOfExp = res.lastIndexOf("E");
        String firstSection = res.substring(0, indexOfExp);
        int idxOfDecimalPoint = firstSection.lastIndexOf(".");
        if (idxOfDecimalPoint == firstSection.length() - 1) {
            firstSection = res.substring(0, idxOfDecimalPoint);
        }
        String secondSection = res.substring(indexOfExp + 1);
        int p = Integer.parseInt(secondSection);
        if (p >= 0) {
            secondSection = "e+" + secondSection;
        } else {
            secondSection = "e" + secondSection;
        }

        return StringUtils.fromString(firstSection + secondSection);
    }