public static void main(String[] args) {
int []arr = new int[2];
try {
arr[2] = 1;
} catch (ArrayIndexOutOfBoundsException e) {
log.error("------- e -------" + e);
log.error("------- e.getMessage() ------- " + e.getMessage());
log.error("------- e.printStackTrace() -------");
e.printStackTrace();
}
}
public class Test {
public static void main(String[] args) {
print("ERROR");
}
private static void print(String error) {
print(error); // StackOverflowError !!
}
}
throw new Execption;
public void methodB() throws Exception {
// Exception 발생
}
public void methodA {
try{
methodB();
} catch(Exception e) {
// e
}
}
메서드 선언부에 선언된 throws문을 통해 어떤 예외가 발생할 수 있는지 예측할 수 있다.
현재 메서드 내에서 예외 처리를 할 필요가 없다고 판단했을 경우
-> 팀원들이 내가 만든 메서드를 사용하는 경우, 팀원마다 예외를 다르게 처리할 수 있다.