JAVA-24938 Article Code Matches first commit (#14820)
This commit is contained in:
+9
-2
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.exceptions.throwvsthrows;
|
||||
|
||||
public class NullOrEmptyException extends RuntimeException {
|
||||
|
||||
public NullOrEmptyException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user