Groupe Genius Java
import [Link];
class NegativeNumberException extends Exception {
public NegativeNumberException(int n) {
super("Erreur : Le nombre " + n + " est négatif.");
}
}
class EvenNumberException extends Exception {
public EvenNumberException(int n) {
super("Erreur : Le nombre " + n + " est pair.");
}
}
public class Chemin {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Donnez un entier : ");
int n = [Link]();
try {
[Link]("Début du bloc try");
verifierNombre(n);
[Link]("Aucune exception levée.");
} catch (NegativeNumberException | EvenNumberException e) {
[Link]([Link]());
} finally {
[Link]("Bloc finally : Fin du traitement.");
}
[Link]("Programme terminé.");
[Link]();
}
public static void verifierNombre(int n) throws NegativeNumberException, EvenNumberException {
if (n < 0) {
throw new NegativeNumberException(n);
}
if (n % 2 == 0) {
throw new EvenNumberException(n);
}
}
}