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:
parent
c8cafe8cd2
commit
8f1d5128c7
|
@ -0,0 +1,5 @@
|
|||
## Core Java Exceptions 2
|
||||
|
||||
This module contains articles about core java exceptions
|
||||
|
||||
###
|
|
@ -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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.rethrow.custom;
|
||||
|
||||
public class InvalidDataException extends Exception {
|
||||
|
||||
public InvalidDataException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue