exception hatali

2 views
Skip to first unread message

Murat Kozan

unread,
Jun 7, 2011, 4:51:42 AM6/7/11
to javacod...@googlegroups.com

public class RindMain{
   
    public static void main (String [] args){
        try{
            Kuh kuh1 = new Kuh("heidi","weiblich",0,10);
            Stier stier1 = new Stier("sariokuz","mannlich",1200,0);
           
       
           
           
            Herde h1 = new Herde("herde1");
           
            h1.add(kuh1);
            h1.add(stier1);
            System.out.println(h1.list());
            System.out.println("-----------List-remove--kuh-------------");
            h1.remove(kuh1);
            System.out.println(h1.list());
           
            System.out.println(h1.getSize());
        } catch (MyException e){
            System.out.println(e.getMessage());
        }
    }
}
______________________________________________________________________

public void setMilkAmount(int milkAmount) throws MyException{
        if( milkAmount == 0){
            throw new MyException("kuh soll milk haben");
        }else{
            this.milkAmount = milkAmount;
        }
    }

___________________________________________________________________


Burdaki hatayi anlamadim
birtürlü
___________________________________________________________________


C:\Users\murat\Desktop\eprog\tutorium>javac RindMain.java
RindMain.java:23: exception MyException is never thrown in body of corresponding
 try statement
                } catch (MyException e){
                  ^
1 error



Murat

Tuncay isler

unread,
Jun 7, 2011, 5:52:05 AM6/7/11
to javacod...@googlegroups.com
Dostum programin herhangi bir yerine asadaki methode yi cagir ve öyle bir dene bakalim, normal de böyle calismasi gerekiyor...

Yani main methodesine public void setMilkAmount(int milkAmount)  methodunu cagir..

Lg. Tuncay


From: kozan...@hotmail.com
To: javacod...@googlegroups.com
Subject: exception hatali
Date: Tue, 7 Jun 2011 08:51:42 +0000
Reply all
Reply to author
Forward
0 new messages