| 
 
| 复制代码package exception;
//报感叹号The serializable class MinusException does not declare a static final serialVersionUID field of type long
class MinusException extends RuntimeException {
        MinusException() {
        }
        MinusException(String msg) {
                super(msg);
        }
}
class Demo {
        public int method(int[] arr, int index) {
                if (index < 0) {
                        throw new MinusException();
                }
                return arr[index];
        }
}
public class ArrayIndexException {
        public static void main(String[] args) {
                int[] arr = new int[3];
                Demo d = new Demo();
                d.method(arr, -20);
        }
}
 | 
 |