BAEL-3397: Difference between throw e and throw new Exception(e) (#8339)

* Article: Quick and practical example of hexagonal architecture in java with Spring Project

* Removed server.port property from application.properties

* BAEL-3397: Difference between throw e and throw new Exception(e) in java

* BAEL-3397 : Removed links from readme file

* BAEL-3397: removed hexagonal module from the code

* BAEL-3397: renamed exceptions package name to rethrow
This commit is contained in:
Vikas Rajput 2019-12-11 21:42:31 +03:00 committed by maibin
parent c8cafe8cd2
commit 8f1d5128c7
5 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,5 @@
## Core Java Exceptions 2
This module contains articles about core java exceptions
###

View File

@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-exceptions-2</artifactId>
<name>core-java-exceptions-2</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<description> </description>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -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);
}
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.rethrow.custom;
public class InvalidDataException extends Exception {
public InvalidDataException(Exception e) {
super(e);
}
}