forked from daveagp/java_visualize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSimpleExcept.java
More file actions
41 lines (40 loc) · 1.19 KB
/
TestSimpleExcept.java
File metadata and controls
41 lines (40 loc) · 1.19 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
37
38
39
40
41
import exceptions.NumException;
public class TestSimpleExcept {
/**
* Positif teste si la valeur du parametre val est positive.
* @param val valeur a tester
* @throws NumException si val est < 0
*/
private static void positif(final double val) throws NumException {
if (val < 0.0) throw new NumException(val, "Valeur positive attendue.");
return;
}
/**
* testPositif utilise positif et relaye l'exception NumException.
* @param val valeur a tester.
* @throws NumException lorsque positif emet NumException
*/
private static void testPositif(double val) throws NumException {
positif(val);
System.out.println("Pas d'exception le code continue en sequence");
return ;
}
/**
* Traitement des arguments de main par test des
* valeurs entieres positives.
* @param argv arguments de la ligne de commande.
*/
public static void main(final String [] argv) {
int i, j = 0;
for (i=0;i<argv.length;i++) {
try {
j = Integer.parseInt(argv[i]);
testPositif(j);
} catch (NumberFormatException nfe){
System.out.println("Parameter " + argv[i] + " should be an integer");
} catch(NumException n){
System.out.println("Catch dans le main " + n);
}
}
}
}