src/share/classes/java/lang/NumberFormatException.java

Print this page
rev 9893 : 8041972: Add improved parse methods for Long/Integer

@@ -54,14 +54,30 @@
     public NumberFormatException (String s) {
         super (s);
     }
 
     /**
-     * Factory method for making a <code>NumberFormatException</code>
+     * Factory method for making a {@code NumberFormatException}
      * given the specified input which caused the error.
      *
      * @param   s   the input causing the error
      */
     static NumberFormatException forInputString(String s) {
         return new NumberFormatException("For input string: \"" + s + "\"");
     }
+
+    /**
+     * Factory method for making a {@code NumberFormatException}
+     * given the specified input which caused the error.
+     *
+     * @param   s   the input causing the error
+     * @param   beginIndex   the beginning index, inclusive.
+     * @param   endIndex     the ending index, exclusive.
+     * @param   errorIndex   the index of the first error in s
+     */
+    static NumberFormatException forCharSequence(CharSequence s,
+            int beginIndex, int endIndex, int errorIndex) {
+        return new NumberFormatException("Error at index "
+                + (errorIndex - beginIndex) + " in: \""
+                + s.subSequence(beginIndex, endIndex) + "\"");
+    }
 }