-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter34.java
More file actions
53 lines (48 loc) Β· 1.69 KB
/
Copy pathChapter34.java
File metadata and controls
53 lines (48 loc) Β· 1.69 KB
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
43
44
45
46
47
48
49
50
51
52
53
package chapter34;
public class ExceptionEx {
public static void main(String[] args) {
//1.0μΌλ‘ λλκ² λλ©΄ μμΈκ° λ°μνλ€!! ->μμΈλ°μλ¨ (νλ‘κ·Έλ¨ μνμ΄ μ€μ§λλ€)
/*
System.out.println(1);
System.out.println(2);
System.out.println(3/0);//0μΌλ‘ λλκ² λλ©΄ μμΈκ° λ°μνλ€!!
System.out.println(4);
System.out.println(5);
System.out.println(6);
*/
//2.μμΈμ²λ¦¬λ₯Ό ν΄μ νλ‘μ€λ¨ μνμ΄ μ€μ§λμ§ μλλ‘ λ§λ€μ΄μΌ νλ€
/*
System.out.println(1);
try{
System.out.println(2);
System.out.println(3);//0μΌλ‘ λλκ² λλ©΄ μμΈκ° λ°μνλ€!!
System.out.println(4);
}catch(ArithmeticException e) {
System.out.println(5);
}
System.out.println(6);
*/
//3.λ€μ€ μμΈ μ²λ¦¬
try{
int[] arr = {1,2,3};
System.out.println(arr[5]);
System.out.println(3/0);
Integer.parseInt("a");
}catch (ArithmeticException e) {
System.out.println("0μΌλ‘ λλ μ μμ");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("μΈλ±μ€ λ²μ μ΄κ³Ό");
}
catch (NumberFormatException e) {
System.out.println("λ¬Έμλ₯Ό μ«μλ‘ λ³κ²½ν μ μμ");
}catch(Exception e) {
System.out.println("κΈ°ν μμΈ λ°μ");
}finally {
System.out.println("μμΈμ μκ΄μμ΄ νμ μνλλ λΈλ‘μ1");
}
//ArrayIndexOutOfBoundsException
//ArithmeticException
//NumberFormatException
}
}