This commit is contained in:
2024-03-18 14:28:35 +01:00
parent a28bef01d7
commit cd3133cbe1
8 changed files with 90 additions and 37 deletions

View File

@@ -0,0 +1,6 @@
public class NullPointerException {
public static void main(String[] args) {
String str = null;
int length = str.length(); // Tentative d'accéder à une méthode sur un objet nul
}
}

View File

@@ -0,0 +1,6 @@
public class NumberFormatException {
public static void main(String[] args) {
String str = "abc";
int num = Integer.parseInt(str); // Conversion d'une chaîne non numérique en entier
}
}

View File

@@ -0,0 +1,5 @@
public class RuntimeExceptionExample {
public static void main(String[] args) {
throw new UnsupportedOperationException("Operation not supported"); // Lancement d'une exception d'opération non supportée
}
}

View 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
}
}

View 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());
}
}
}

View File

@@ -0,0 +1,13 @@
import java.io.IOException;
public class Incomplet {
public static void main(String[] args) {
byte[] txt = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A};
try {
System.out.write(txt);
System.out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}