-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryCatch1.java
More file actions
36 lines (31 loc) · 1.11 KB
/
TryCatch1.java
File metadata and controls
36 lines (31 loc) · 1.11 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
package mart17;
public class TryCatch1 {
public static void main(String[] args) {
int sayi = 0;
int veri[] = { 1, 2, 3 };
try {
sayi = 10 / 0;
System.out.println(veri[4]);
System.out.println("Try bloğunda hata yok. Catch bloğu çalıştırmaz.");
System.out.println("Try bloğu sonrası sayi değişkeni: " + sayi);
}
// Aritmetik işlem hatası yakalama catch'i
catch (ArithmeticException e) {
sayi = 10 / 1;
System.out.println("Aritmetik işlem hatası.");
System.out.println("Try bloğu hatalı. Catch bloğu çalıştırıldı.");
System.out.println("Hatanın tamamı: " + e);
System.out.println("Hata mesajı: " + e.getMessage());
System.out.println("Catch bloğu sonrası sayi değişkeni: " + sayi);
}
// Array sınırı hatası yakalama catch'i
catch (ArrayIndexOutOfBoundsException e) {
System.out.println(veri[veri.length - 1]);
System.out.println("Array sınır aşımı hatası.");
} finally {
System.out.println("\nHer koşulda çalışır.");
}
System.out.println(sayi);
System.out.println("Program bitti.");
}
}