15 lines
482 B
Java
15 lines
482 B
Java
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
|
|
}
|
|
}
|