JAVA-24938 Article Code Matches first commit (#14820)

This commit is contained in:
anuragkumawat
2023-10-21 14:27:49 +05:30
committed by GitHub
parent adb490c874
commit b0ed62e8c8
5 changed files with 38 additions and 4 deletions
@@ -20,8 +20,9 @@ public class Main {
System.out.println("General exception");
}
checkedException();
checkedExceptionWithTryCatch();
checkedExceptionWithThrows();
divideByZero();
}
private static void checkedExceptionWithThrows() throws FileNotFoundException {
@@ -29,7 +30,7 @@ public class Main {
FileInputStream stream = new FileInputStream(file);
}
private static void checkedException() {
private static void checkedExceptionWithTryCatch() {
File file = new File("not_existing_file.txt");
try {
FileInputStream stream = new FileInputStream(file);
@@ -37,5 +38,11 @@ public class Main {
e.printStackTrace();
}
}
private static void divideByZero() {
int numerator = 1;
int denominator = 0;
int result = numerator / denominator;
}
}
@@ -0,0 +1,8 @@
package com.baeldung.exceptions.throwvsthrows;
public class NullOrEmptyException extends RuntimeException {
public NullOrEmptyException(String errorMessage) {
super(errorMessage);
}
}