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);
+ }
}
- csr of
-
JDK-8161558 ListIterator should not discard cause on exception
-
- Resolved
-