tp10
This commit is contained in:
14
DEV2.1/Exception/ex2/ArithmeticExceptionExample.java
Normal file
14
DEV2.1/Exception/ex2/ArithmeticExceptionExample.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class ArithmeticExceptionExample {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
computeDivision(); // Appel de la méthode responsable de l'exception
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("Une erreur arithmétique s'est produite : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode responsable de l'exception
|
||||
public static void computeDivision() {
|
||||
int result = 10 / 0; // Division par zéro
|
||||
}
|
||||
}
|
||||
9
DEV2.1/Exception/ex2/Main.java
Normal file
9
DEV2.1/Exception/ex2/Main.java
Normal file
@@ -0,0 +1,9 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ArithmeticExceptionVrai.computeDivision();
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("Une erreur arithmétique s'est produite : " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user