diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md index 1b8457acc4..46ffd490be 100644 --- a/core-java-modules/core-java-exceptions-2/README.md +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -9,3 +9,6 @@ This module contains articles about core java exceptions - [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception) - [How to Handle Java SocketException](https://www.baeldung.com/java-socketexception) - [Java Suppressed Exceptions](https://www.baeldung.com/java-suppressed-exceptions) +- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) +- [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler) +- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) diff --git a/core-java-modules/core-java-exceptions-2/pom.xml b/core-java-modules/core-java-exceptions-2/pom.xml index cf8de3d5b6..915ec1da69 100644 --- a/core-java-modules/core-java-exceptions-2/pom.xml +++ b/core-java-modules/core-java-exceptions-2/pom.xml @@ -23,6 +23,11 @@ ${assertj-core.version} test + + org.apache.commons + commons-lang3 + ${commons.lang3.version} + @@ -30,6 +35,7 @@ UTF-8 + 3.10 3.10.0 diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/Arithmetic.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/Arithmetic.java similarity index 87% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/Arithmetic.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/Arithmetic.java index db29198b39..57d022eb13 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/Arithmetic.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/Arithmetic.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ArrayIndexOutOfBounds.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ArrayIndexOutOfBounds.java similarity index 92% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ArrayIndexOutOfBounds.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ArrayIndexOutOfBounds.java index 54c95f224c..b7c8bb1875 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ArrayIndexOutOfBounds.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ArrayIndexOutOfBounds.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ClassCast.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ClassCast.java similarity index 92% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ClassCast.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ClassCast.java index 8f8a6cf9e6..1ef8399d3d 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ClassCast.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ClassCast.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/FileNotFound.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/FileNotFound.java similarity index 91% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/FileNotFound.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/FileNotFound.java index a9f2e5ee84..a94e294016 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/FileNotFound.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/FileNotFound.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import java.io.BufferedReader; import java.io.File; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandler.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandler.java similarity index 92% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandler.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandler.java index f2e89f44e3..4d3f7c1a98 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandler.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandler.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalArgument.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalArgument.java similarity index 87% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalArgument.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalArgument.java index d54757dfac..cb7f981e17 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalArgument.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalArgument.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalState.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalState.java similarity index 92% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalState.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalState.java index 0a812d2b82..105ca155b7 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/IllegalState.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/IllegalState.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import java.util.ArrayList; import java.util.Iterator; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/InterruptedExceptionExample.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/InterruptedExceptionExample.java similarity index 91% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/InterruptedExceptionExample.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/InterruptedExceptionExample.java index d0c8bb2cd0..3b37168013 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/InterruptedExceptionExample.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/InterruptedExceptionExample.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/MalformedURL.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/MalformedURL.java similarity index 89% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/MalformedURL.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/MalformedURL.java index 9a02f005fd..cc1f39ea69 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/MalformedURL.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/MalformedURL.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import java.net.MalformedURLException; import java.net.URL; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NullPointer.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NullPointer.java similarity index 93% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NullPointer.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NullPointer.java index 445cbecdc8..6d6a1706a6 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NullPointer.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NullPointer.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NumberFormat.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NumberFormat.java similarity index 90% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NumberFormat.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NumberFormat.java index 576fe51f78..7497d023ee 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/NumberFormat.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/NumberFormat.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ParseExceptionExample.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ParseExceptionExample.java similarity index 90% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ParseExceptionExample.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ParseExceptionExample.java index e3b3e04b10..7def606786 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/ParseExceptionExample.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/ParseExceptionExample.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import java.text.DateFormat; import java.text.ParseException; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/StringIndexOutOfBounds.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/StringIndexOutOfBounds.java similarity index 91% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/StringIndexOutOfBounds.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/StringIndexOutOfBounds.java index 0ee132e568..8652926777 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/globalexceptionhandler/StringIndexOutOfBounds.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/globalexceptionhandler/StringIndexOutOfBounds.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinder.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rootcausefinder/RootCauseFinder.java similarity index 98% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinder.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rootcausefinder/RootCauseFinder.java index 06610f3874..cb04902dfa 100644 --- a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinder.java +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rootcausefinder/RootCauseFinder.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.rootcausefinder; +package com.baeldung.rootcausefinder; import java.time.LocalDate; import java.time.Period; diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableMain.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableMain.java similarity index 100% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableMain.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableMain.java diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesFirst.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesFirst.java similarity index 100% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesFirst.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesFirst.java diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesSecond.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesSecond.java similarity index 100% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesSecond.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/AutoCloseableResourcesSecond.java diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/MyResource.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/MyResource.java similarity index 100% rename from core-java-modules/core-java-exceptions/src/main/java/com/baeldung/trywithresource/MyResource.java rename to core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/trywithresource/MyResource.java diff --git a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java b/core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java similarity index 97% rename from core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java rename to core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java index 74ceb3b442..83347f9d9d 100644 --- a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java +++ b/core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/globalexceptionhandler/GlobalExceptionHandlerUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions.globalexceptionhandler; +package com.baeldung.globalexceptionhandler; import org.junit.After; import org.junit.Before; diff --git a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinderUnitTest.java b/core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/rootcausefinder/RootCauseFinderUnitTest.java similarity index 80% rename from core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinderUnitTest.java rename to core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/rootcausefinder/RootCauseFinderUnitTest.java index f42388857a..ccf14c4cba 100644 --- a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/rootcausefinder/RootCauseFinderUnitTest.java +++ b/core-java-modules/core-java-exceptions-2/src/test/java/com/baeldung/rootcausefinder/RootCauseFinderUnitTest.java @@ -1,7 +1,7 @@ -package com.baeldung.exceptions.rootcausefinder; +package com.baeldung.rootcausefinder; -import com.baeldung.exceptions.rootcausefinder.RootCauseFinder.CalculationException; -import com.baeldung.exceptions.rootcausefinder.RootCauseFinder.DateOutOfRangeException; +import com.baeldung.rootcausefinder.RootCauseFinder.CalculationException; +import com.baeldung.rootcausefinder.RootCauseFinder.DateOutOfRangeException; import com.google.common.base.Throwables; import org.apache.commons.lang3.exception.ExceptionUtils; import org.junit.jupiter.api.Assertions; @@ -11,8 +11,7 @@ import java.time.LocalDate; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; -import static com.baeldung.exceptions.rootcausefinder.RootCauseFinder.AgeCalculator; -import static com.baeldung.exceptions.rootcausefinder.RootCauseFinder.findCauseUsingPlainJava; +import static com.baeldung.rootcausefinder.RootCauseFinder.AgeCalculator; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -38,7 +37,7 @@ public class RootCauseFinderUnitTest { try { AgeCalculator.calculateAge("010102"); } catch (CalculationException ex) { - assertTrue(findCauseUsingPlainJava(ex) instanceof DateTimeParseException); + assertTrue(RootCauseFinder.findCauseUsingPlainJava(ex) instanceof DateTimeParseException); } } @@ -47,7 +46,7 @@ public class RootCauseFinderUnitTest { try { AgeCalculator.calculateAge("2020-04-04"); } catch (CalculationException ex) { - assertTrue(findCauseUsingPlainJava(ex) instanceof DateOutOfRangeException); + assertTrue(RootCauseFinder.findCauseUsingPlainJava(ex) instanceof DateOutOfRangeException); } } @@ -56,7 +55,7 @@ public class RootCauseFinderUnitTest { try { AgeCalculator.calculateAge(null); } catch (Exception ex) { - assertTrue(findCauseUsingPlainJava(ex) instanceof IllegalArgumentException); + assertTrue(RootCauseFinder.findCauseUsingPlainJava(ex) instanceof IllegalArgumentException); } } diff --git a/core-java-modules/core-java-exceptions/README.md b/core-java-modules/core-java-exceptions/README.md index b7222540e9..5f47aa69fb 100644 --- a/core-java-modules/core-java-exceptions/README.md +++ b/core-java-modules/core-java-exceptions/README.md @@ -12,9 +12,5 @@ This module contains articles about core java exceptions - [“Sneaky Throws” in Java](https://www.baeldung.com/java-sneaky-throws) - [The StackOverflowError in Java](https://www.baeldung.com/java-stack-overflow-error) - [Checked and Unchecked Exceptions in Java](https://www.baeldung.com/java-checked-unchecked-exceptions) -- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) -- [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler) - [Common Java Exceptions](https://www.baeldung.com/java-common-exceptions) -- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) -- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice) - [[Next -->]](/core-java-modules/core-java-exceptions-2) \ No newline at end of file