ArrayIndexOutOfBoundsException : 배열에서 인덱스 범위를 초과하여 사용할 경우 발생하는 예외
ArrayIndexOutOfBoundsException
package sec02_runtime_exception;
public class ArrayIndexOutOfBoundsExceptionExample {
public static void main(String[] args) {
//Run Configuration - Arguments에 값 지정 안되면 ArrayIndexOutOfBoundsException 발생
String data1 = args[0];
String data2 = args[1];
System.out.println("args[0]: " + args[0]);
System.out.println("args[1]: " + args[1]);
/*
if(args.length == 2) {
String data1 = args[0];
String data2 = args[1];
System.out.println("args[0]: " + args[0]);
System.out.println("args[1]: " + args[1]);
} else {
System.out.println("[실행 방법]");
System.out.println("java ArrayIndexOutOfBoundsExceptionExample 값1 값2");
}
*/
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at sec02_runtime_exception.ArrayIndexOutOfBoundsExceptionExample.main(ArrayIndexOutOfBoundsExceptionExample.java:7)
'Java > 10. 예외 처리 (Exception)' 카테고리의 다른 글
Day 14 : 예외 처리 코드 - try-catch-finally 블록 (0) | 2021.11.05 |
---|---|
Day 14 : ClassCastException (0) | 2021.11.05 |
Day 14 : NumberFormatException (0) | 2021.11.05 |
Day 14 : NullPointerException (0) | 2021.11.05 |
Day 14 : 예외 (Exception) (0) | 2021.11.05 |