728x90
반응형
package chap9;
/*
* throws : 예외처리
* 예외 던지기 => 현재 메서드를 호출한 메서드로 예외 전송
*/
public class ExceptionEx4 {
public static void main(String[] args) {
try {
first();
} catch (Exception e) {
System.out.println("숫자만 가능합니다.");
e.printStackTrace();
}
}
private static void first() throws Exception {
System.out.println("first 메서드");
second();
}
private static void second() throws Exception {
System.out.println("second 메서드");
System.out.println(Integer.parseInt("abc")); //NumberFormatException 예외발생
}
}
728x90
반응형
'study > Java' 카테고리의 다른 글
[Java] 26. Exception6 (throw 예제) (0) | 2022.03.22 |
---|---|
[Java] 26. Exception5 (throw) (0) | 2022.03.22 |
[Java] 26. Exception3 (finally) (0) | 2022.03.22 |
[Java] 26. Exception2 (다중 catch 구문) (0) | 2022.03.22 |
[Java] 26. Exception1 (try, catch) (0) | 2022.03.22 |