diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md new file mode 100644 index 0000000000..3ad5189b5e --- /dev/null +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -0,0 +1,5 @@ +## Core Java Exceptions 2 + +This module contains articles about core java exceptions + +### diff --git a/core-java-modules/core-java-exceptions-2/pom.xml b/core-java-modules/core-java-exceptions-2/pom.xml new file mode 100644 index 0000000000..2f7f613faf --- /dev/null +++ b/core-java-modules/core-java-exceptions-2/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + core-java-exceptions-2 + core-java-exceptions-2 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + http://maven.apache.org + + + UTF-8 + + + diff --git a/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowDifferentExceptionDemo.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowDifferentExceptionDemo.java new file mode 100644 index 0000000000..ce2fcb2c7a --- /dev/null +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowDifferentExceptionDemo.java @@ -0,0 +1,29 @@ +package com.baeldung.rethrow; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.baeldung.rethrow.custom.InvalidDataException; + +public class RethrowDifferentExceptionDemo { + + private final static Logger LOGGER = Logger.getLogger(RethrowDifferentExceptionDemo.class.getName()); + + public static void main(String[] args) throws Exception { + String name = null; + + try { + + // Below line will throw NullPointerException + if (name.equals("Joe")) { + // Do blah blah.. + } + + } catch (Exception e) { + LOGGER.log(Level.WARNING, "So and so user is unable to cast vote because he is found uneligible"); + throw new InvalidDataException(e); + } + + } + +} diff --git a/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowSameExceptionDemo.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowSameExceptionDemo.java new file mode 100644 index 0000000000..bf53f67d34 --- /dev/null +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/RethrowSameExceptionDemo.java @@ -0,0 +1,27 @@ +package com.baeldung.rethrow; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class RethrowSameExceptionDemo { + + private final static Logger LOGGER = Logger.getLogger(RethrowDifferentExceptionDemo.class.getName()); + + public static void main(String[] args) throws Exception { + String name = null; + + try { + + // Below line will throw NullPointerException + if (name.equals("Joe")) { + // Do blah blah.. + } + + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Exception occurred due to invalid name"); + throw e; + } + + } + +} diff --git a/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/custom/InvalidDataException.java b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/custom/InvalidDataException.java new file mode 100644 index 0000000000..5a74e32012 --- /dev/null +++ b/core-java-modules/core-java-exceptions-2/src/main/java/com/baeldung/rethrow/custom/InvalidDataException.java @@ -0,0 +1,8 @@ +package com.baeldung.rethrow.custom; + +public class InvalidDataException extends Exception { + + public InvalidDataException(Exception e) { + super(e); + } +}