-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionJava.java
More file actions
49 lines (41 loc) · 1.17 KB
/
Copy pathExceptionJava.java
File metadata and controls
49 lines (41 loc) · 1.17 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
public class ExceptionJava {
public static void main(String[] args) {
// try catch
// int angkaPertama = 10;
// int angkaKedua = 0;
//
// try {
// int hasil = angkaPertama / angkaKedua;
// System.out.println(hasil);
// } catch ( error) {
// System.out.println("operasi matematika tidak valid");
// }
// int[] nilai = {80, 90, 100};
// int angkaPertama = 10;
// int angkaKedua = 0;
//
//
// try {
// System.out.println(nilai[1]);
// System.out.println("hasil: " + (angkaPertama / angkaKedua));
// } catch (ArrayIndexOutOfBoundsException error) {
// System.out.println("yang kamu akses diluar batas indeks");
// } catch (ArithmeticException error) {
// System.out.println("tidak bisa dibagikan dengan nol.");
// } finally {
// System.out.println("semua operasi sudah dijalankan");
// }
try {
bagiAngka();
} catch (ArithmeticException error ) {
System.out.println("pembagian dengan nol tidak valid");
}
}
static void bagiAngka() {
int hasil = 10 / 0;
}
// IOException
// SQLException
// FileNotFoundException
// RuntimeException
}