1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. Oracle designates this 9 * particular file as subject to the "Classpath" exception as provided 10 * by Oracle in the LICENSE file that accompanied this code. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23 * or visit www.oracle.com if you need additional information or have any 24 * questions. 25 */ 26 27 package java.lang; 28 29 /** 30 * Thrown by <code>String</code> methods to indicate that an index 31 * is either negative or greater than the size of the string. For 32 * some methods such as the charAt method, this exception also is 33 * thrown when the index is equal to the size of the string. 34 * 35 * @author unascribed 36 * @see java.lang.String#charAt(int) 37 * @since JDK1.0 38 */ 39 public 40 class StringIndexOutOfBoundsException extends IndexOutOfBoundsException { 41 private static final long serialVersionUID = -6762910422159637258L; 42 43 /** 44 * Constructs a <code>StringIndexOutOfBoundsException</code> with no 45 * detail message. 46 * 47 * @since JDK1.0. 48 */ StringIndexOutOfBoundsException()49 public StringIndexOutOfBoundsException() { 50 super(); 51 } 52 53 /** 54 * Constructs a <code>StringIndexOutOfBoundsException</code> with 55 * the specified detail message. 56 * 57 * @param s the detail message. 58 */ StringIndexOutOfBoundsException(String s)59 public StringIndexOutOfBoundsException(String s) { 60 super(s); 61 } 62 63 /** 64 * Constructs a new <code>StringIndexOutOfBoundsException</code> 65 * class with an argument indicating the illegal index. 66 * 67 * @param index the illegal index. 68 */ StringIndexOutOfBoundsException(int index)69 public StringIndexOutOfBoundsException(int index) { 70 super("String index out of range: " + index); 71 } 72 73 /** 74 * Used internally for consistent high-quality error reporting. 75 * @hide 76 */ StringIndexOutOfBoundsException(String s, int index)77 public StringIndexOutOfBoundsException(String s, int index) { 78 this(s.length(), index); 79 } 80 81 /** 82 * Used internally for consistent high-quality error reporting. 83 * @hide 84 */ StringIndexOutOfBoundsException(int sourceLength, int index)85 public StringIndexOutOfBoundsException(int sourceLength, int index) { 86 super("length=" + sourceLength + "; index=" + index); 87 } 88 89 /** 90 * Used internally for consistent high-quality error reporting. 91 * @hide 92 */ StringIndexOutOfBoundsException(String s, int offset, int count)93 public StringIndexOutOfBoundsException(String s, int offset, int count) { 94 this(s.length(), offset, count); 95 } 96 97 /** 98 * Used internally for consistent high-quality error reporting. 99 * @hide 100 */ StringIndexOutOfBoundsException(int sourceLength, int offset, int count)101 public StringIndexOutOfBoundsException(int sourceLength, int offset, 102 int count) { 103 super("length=" + sourceLength + "; regionStart=" + offset 104 + "; regionLength=" + count); 105 } 106 } 107