| [Précédent] |
| 13.2 |
Compile .. ou pas - Enoncé | Niveau 1 |
||
But: |
Vérifiez vos connaissances sur les exceptions | |||
Thème: |
exceptions | |||
Fichiers: |
Exemple.java | |||
Ajoutez au programme fourni des commentaires répondant aux questions posées.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
class Exemple {
/*Expliquer pourquoi ce code ne compile pas
*/
public void m1() {
foo();
}
public int foo() throws Exception {
throw new Exception();
}
/*Expliquer pourquoi ce code n'est pas considéré comme bon
*/
public void m2() {
try {
//do stuff...
} catch (Exception e) {
}
}
/*Expliquer pourquoi ce code ne compile pas
*/
public void m3() {
try {
//do stuff...
} catch (Exception e) {
} catch (NullPointerException e) {
}
}
/*Expliquer pourquoi ce code ne compile pas
*/
public void m4() {
throw new CustomCheckedException();
}
private class CustomCheckedException extends Exception {
private static final long serialVersionUID = -7944813576443065516L;
public CustomCheckedException() {
//nothing
}
}
/*Expliquer pourquoi ce code ne compile pas
*/
public int m5() {
int age;
String s = "24";
try {
age = getAccessCode();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return age;
}
public int getAccessCode() throws IllegalAccessException {
throw new IllegalAccessException();
}
/*Expliquer pourquoi ce code COMPILE
*/
public void m6() {
bar();
}
public int bar() {
throw new RuntimeException();
}
} |
| [Précédent] |