- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter37.java
More file actions
Latest commit
24 lines (23 loc) · 999 Bytes
/
Copy pathChapter37.java
File metadata and controls
24 lines (23 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
packagechapter37;
publicclassExceptionEx3 {
//throws 키워드 : 떠넘기다
//현재 메서드가 예외처리를 하지 않고 자신을 호출한 쪽으로 에외처리를 떠넘긴다
publicstaticintdivide(intnum,intnum1) throwsArithmeticException {
intd = num/num1;
returnd;
}
publicstaticvoidmain(String[] args) {
intnum =10;
intnum1 = 0;
try {
//throws로 넘겨받은 메서드내의 예외처리를 함수를 호출한 이곳으로 catch 블록으로 처리한다
intresult = divide(num,num1);
System.out.println("divide(num,num1)함수 수행 결과값 = "+result);
}catch(ArithmeticExceptione) {
System.out.println(e.toString());
}finally {
System.out.println("예외가 발생하지 않아도 무조건 수행해야 한다");
}
System.out.println("---------------------------");
System.out.println("main() 함수 수행 끝");
}