
{filelink=4349}
public class DemoException {
public static void main(String[] arg) {
new DemoException().TesterException();
}
public Object ExceptionSi(int type) throws IllegalArgumentException {
if (type == 1) // Si la méthode est appelée avec la valeur '1' . alors générer une exception
throw new IllegalArgumentException("Le nombre 1 est rejeté " + type);
return new Object();
}
public void TesterException() {
Object objet = null;
for (int i=0; i<5; i++) {
try {
objet = ExceptionSi(i);
} catch (IllegalArgumentException err) {
System.err.println("Erreur: (" + err.getMessage() + ").");
return;
}
System.out.println(objet);
}
}
}