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

Add constructor overloads to NoSuchElementException

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 15
    • core-libs
    • None
    • minimal
    • Existing behavior includes the cause for the issue.
    • Java API
    • SE

      Summary

      Add constructor overloads to NoSuchElementException so that it provides the standard four Throwable constructors.

      Problem

      NoSuchElementException doesn't have the constructor overloads (Throwable) and (String, Throwable). This means that it's inconvenient to add extra context to the exception.

      Solution

      Add (Throwable) and (String, Throwable) constructor overloads, so that NoSuchElementException will have the "standard" four constructors.

      Specification

      --- old/src/java.base/share/classes/java/util/NoSuchElementException.java   2019-11-08 18:04:04.879437936 +0000
      +++ new/src/java.base/share/classes/java/util/NoSuchElementException.java   2019-11-08 18:04:04.623425449 +0000
      @@ -57,4 +57,29 @@
           public NoSuchElementException(String s) {
               super(s);
           }
      +
      +    /**
      +     * Constructs a {@code NoSuchElementException} with the specified detail
      +     * message and cause.
      +     *
      +     * @param  s the detail message
      +     * @param  cause the cause (which is saved for later retrieval by the
      +     *         {@link #getCause()} method), or null
      +     * @since 15
      +     */
      +    public NoSuchElementException(String s, Throwable cause) {
      +        super(s, cause);
      +    }
      +
      +    /**
      +     * Constructs a {@code NoSuchElementException} with the specified cause.
      +     * The detail message is set to {@code (cause == null ? null :
      +     * cause.toString())} (which typically contains the class and
      +     * detail message of {@code cause}).
      +     *
      +     * @param  cause the cause (which is saved for later retrieval by the
      +     *         {@link #getCause()} method)
      +     * @since 15
      +     */
      +    public NoSuchElementException(Throwable cause) {
      +        super(cause);
      +    }
       }

            kravikumar Kiran Sidhartha Ravikumar (Inactive)
            webbuggrp Webbug Group
            Martin Buchholz, Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: