Skip to content

Commit f426585

Browse files
vikasrajputinmaibin
authored andcommitted
BAEL-3397: Difference between throw e and throw new Exception(e) (eugenp#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
1 parent fdf40ec commit f426585

5 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Core Java Exceptions 2
2+
3+
This module contains articles about core java exceptions
4+
5+
###
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>core-java-exceptions-2</artifactId>
7+
<name>core-java-exceptions-2</name>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-java</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../../parent-java</relativePath>
15+
</parent>
16+
17+
<description> </description>
18+
<url>http://maven.apache.org</url>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.rethrow;
2+
3+
import java.util.logging.Level;
4+
import java.util.logging.Logger;
5+
6+
import com.baeldung.rethrow.custom.InvalidDataException;
7+
8+
public class RethrowDifferentExceptionDemo {
9+
10+
private final static Logger LOGGER = Logger.getLogger(RethrowDifferentExceptionDemo.class.getName());
11+
12+
public static void main(String[] args) throws Exception {
13+
String name = null;
14+
15+
try {
16+
17+
// Below line will throw NullPointerException
18+
if (name.equals("Joe")) {
19+
// Do blah blah..
20+
}
21+
22+
} catch (Exception e) {
23+
LOGGER.log(Level.WARNING, "So and so user is unable to cast vote because he is found uneligible");
24+
throw new InvalidDataException(e);
25+
}
26+
27+
}
28+
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.rethrow;
2+
3+
import java.util.logging.Level;
4+
import java.util.logging.Logger;
5+
6+
public class RethrowSameExceptionDemo {
7+
8+
private final static Logger LOGGER = Logger.getLogger(RethrowDifferentExceptionDemo.class.getName());
9+
10+
public static void main(String[] args) throws Exception {
11+
String name = null;
12+
13+
try {
14+
15+
// Below line will throw NullPointerException
16+
if (name.equals("Joe")) {
17+
// Do blah blah..
18+
}
19+
20+
} catch (Exception e) {
21+
LOGGER.log(Level.WARNING, "Exception occurred due to invalid name");
22+
throw e;
23+
}
24+
25+
}
26+
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.rethrow.custom;
2+
3+
public class InvalidDataException extends Exception {
4+
5+
public InvalidDataException(Exception e) {
6+
super(e);
7+
}
8+
}

0 commit comments

Comments
 (0)