tp10
This commit is contained in:
6
DEV2.1/Exception/ex1/NullPointerException.java
Normal file
6
DEV2.1/Exception/ex1/NullPointerException.java
Normal 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
|
||||
}
|
||||
}
|
||||
6
DEV2.1/Exception/ex1/NumberFormatException.java
Normal file
6
DEV2.1/Exception/ex1/NumberFormatException.java
Normal 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
|
||||
}
|
||||
}
|
||||
5
DEV2.1/Exception/ex1/RuntimeExceptionExample.java
Normal file
5
DEV2.1/Exception/ex1/RuntimeExceptionExample.java
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user