Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8314611

Provide more explicative error message parsing Currencies

XMLWordPrintable

    • b14
    • generic
    • generic

        A DESCRIPTION OF THE PROBLEM :
        java.util.Currency.getInstance method throw IllegalArgumentException without any error message. As an enhancement a more meaningful error message could be produce.
        Before :
                    boolean found = false;
                    if (currencyCode.length() != 3) {
                        throw new IllegalArgumentException();
                    }

        After :
                    boolean found = false;
                    if (currencyCode.length() != 3) {
                        throw new IllegalArgumentException("Currency code not 3 characters length");
                    }
        Before :
                    if (!found) {
                        OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode);
                        if (ocEntry == null) {
                            throw new IllegalArgumentException("Currency code not found");
                        }
                        ...
                    }
        After :

                    if (!found) {
                        OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode);
                        if (ocEntry == null) {
                            throw new IllegalArgumentException("Currency code not found");
                        }
                        ...
                    }

        As a comparable in java.time.format.DateTimeFormatter some error message are added in the exception message :

            public TemporalAccessor parseBest(CharSequence text, TemporalQuery<?>... queries) {
                Objects.requireNonNull(text, "text");
                Objects.requireNonNull(queries, "queries");
                if (queries.length < 2) {
                    throw new IllegalArgumentException("At least two queries must be specified");
                }


              jlu Justin Lu
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: