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

Provide more explicative error message parsing Currencies

    XMLWordPrintable

Details

    • b14
    • generic
    • generic

    Description

      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");
              }


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: