-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava154_exception.java
More file actions
42 lines (34 loc) · 918 Bytes
/
Copy pathJava154_exception.java
File metadata and controls
42 lines (34 loc) · 918 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package java0908_api;
public class Java154_exception {
public static void main(String[] args) {
String data1 = "12";
String data2 = "0";
try {
int x = Integer.parseInt(data1);
int y = Integer.parseInt(data2);
int res = x / y;
System.out.println(res);
} catch (NumberFormatException ex) {
System.out.println("숫자를 입력하세요.");
} catch (ArithmeticException e) {
System.out.println("분모는 0보다 큰 수를 입력하세요.");
} catch (RuntimeException e) {
System.out.println(e.toString());
} catch (Exception e) {
System.out.println(e.toString());
}
System.out.println("program end");
}
}
/* 상속 관계
*
* catch 처리할때 가장 작은것 부터 큰 순으로 해야한다. ex) NumberFormatException -> .. -> Exception
*
* Exception
*
* RuntimeException
*
* NumberFormatException ArithmeticException
*
*
* */