Java Exception Sorusu
-
Selamlar kod altındaki gibi çıktı verecek bir kod yazmam lazım method1,2,3 içeriği doldurulacak sadece. Mantık konusunda sıkıntı yaşıyorum.zincir halinde exception atmamız lazım. Yardım edebilecek var mı.
-
try{
if(duruma göre girilecek kod)
{
System.out.println("Kuyruğa girdim fırladım : " + method1);
}
}
-
konuyu biraz açarmısın?
-
method1 icinde method2 yi cagir, method2 icinde method3 u cagir, method3 icinde method 4 u cagir. yolladigin resimdeki ciktiyi almak istiyosan, main methodunda ki try-catch blogunu kaldirman gerek. try- catch resimdeki gibi hata vermesini engeller, try icinde exception olustugunda catch onu yakalar, catch icindeki kod calistirilir.
-
moi bunu yazdı
method1 icinde method2 yi cagir, method2 icinde method3 u cagir, method3 icinde method 4 u cagir. yolladigin resimdeki ciktiyi almak istiyosan, main methodunda ki try-catch blogunu kaldirman gerek. try- catch resimdeki gibi hata vermesini engeller, try icinde exception olustugunda catch onu yakalar, catch icindeki kod calistirilir.
abi soruda hiç bir şey silinmeyecek o main içi kaldırılamıyor. Sadece method1,2,3 içine bir şeyler yazarak altta verilen çıktıya ulaşmam lazım.
Yani anlayacağınız mevcut kodun çıktısı değil o düzenlemelerle ulaşmam gereken çıktı.
-
Hocam örnekte de göreceğin üzere olay Exception'u oluştururken reason kısmına önceki exceptionun referansını vermek.
package com.dota2trader.j4x; public class Deneme { public static void main(String[] args) { try { method1(); } catch (Exception e) { e.printStackTrace(); } } public static void method1() throws Exception { try { method2(); } catch (Exception e) { throw new Exception("Catch block of method1", e); } } public static void method2() throws Exception { try { method3(); } catch (Exception e) { throw new Exception("Catch block of method2", e); } } public static void method3() throws Exception { try { method4(); } catch (Exception e) { throw new Exception("Catch block of method3", e); } } public static void method4() throws Exception { throw new Exception("Exception thrown from method4"); } }
-
edit: düzenlemişsin yeni gördüm :) başta yazdığının aynısını yazmıştım şimdi anladım sıkıntıyı. çok teşekkür ederim sana ve ilgilenen herkese
whopper tarafından 27/Tem/15 20:05 tarihinde düzenlenmiştir -
Hocam düzenledim postu simdi verdigim tam aynı outputu veriyor.
java.lang.Exception: Catch block of method1
j4x tarafından 27/Tem/15 20:04 tarihinde düzenlenmiştir
at com.dota2trader.j4x.Denek.method1(Denek.java:23)
at com.dota2trader.j4x.Denek.main(Denek.java:8)
Caused by: java.lang.Exception: Catch block of method2
at com.dota2trader.j4x.Denek.method2(Denek.java:34)
at com.dota2trader.j4x.Denek.method1(Denek.java:19)
... 1 more
Caused by: java.lang.Exception: Catch block of method3
at com.dota2trader.j4x.Denek.method3(Denek.java:45)
at com.dota2trader.j4x.Denek.method2(Denek.java:30)
... 2 more
Caused by: java.lang.Exception: Exception thrown from method4
at com.dota2trader.j4x.Denek.method4(Denek.java:51)
at com.dota2trader.j4x.Denek.method3(Denek.java:41)
... 3 more