Bonjour, alors je viens de commencer à toucher aux exceptions.

Cependant j'ai un probléme que je n'arrive pas à résoudre depuis un petit moment.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
class ErrConst extends Exception {}
class ErrDep extends Exception {}
 
class Point_exeption{
 
    private int x ;
    private  int y ;
 
     public Point_exeption(int x, int y)throws ErrConst{
 
        if ( (x<0) || (y<0) ) throw new ErrConst();
 
        this.x = x ;
        this.y = y ;
    }
 
    public void deplace(int dx , int dy) throws ErrDep{
 
        if((dx<0)||(dy<0)) throw new ErrDep();
 
        x+=dx ;
        y+=dy ;
    }
 
    public static void main(String args []){
 
        try{
            Point_exeption a = new Point_exeption(1,4);
            a.affiche();
            a.deplace(-3, 5);
 
            a= new Point_exeption(-3 , 5) ;
            a.affiche();
        }  
        catch(ErrConst e){
 
            System.out.println("erreur au niveau du constructeur");
            System.exit(-1);
        }
         catch(ErrDep e){
 
            System.out.println("erreur au niveau du déplacement");
            System.exit(-1);
        }
    }    
    public void affiche(){
 
        System.out.println("les coorddonnées x = " +x +" et y = " +y);
    }
 
 
}
Exception ErrConst is never thrown in body of corresponding try statment ?

Pourtant j'ai bien vérifié et respecter la syntaxe pour levé explicitement une exception.
Est ce que qq voit ou est ce qu'elle est l'erreur.

J'utilise netbeans 6 comme IDE .