-
Notifications
You must be signed in to change notification settings - Fork 54.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from sbmaggarwal/master
Added chainedexceptions in core-java
- Loading branch information
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,7 @@ | |
*.txt | ||
/bin/ | ||
/temp | ||
|
||
#IntelliJ specific | ||
.idea | ||
*.iml |
44 changes: 44 additions & 0 deletions
44
core-java/src/main/java/com/baeldung/chainedexception/LogWithChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.baeldung.chainedexception; | ||
|
||
import com.baeldung.chainedexception.exceptions.GirlFriendOfManagerUpsetException; | ||
import com.baeldung.chainedexception.exceptions.ManagerUpsetException; | ||
import com.baeldung.chainedexception.exceptions.NoLeaveGrantedException; | ||
import com.baeldung.chainedexception.exceptions.TeamLeadUpsetException; | ||
|
||
public class LogWithChain { | ||
|
||
public static void main(String[] args) throws Exception { | ||
getLeave(); | ||
} | ||
|
||
private static void getLeave() throws NoLeaveGrantedException { | ||
try { | ||
howIsTeamLead(); | ||
} catch (TeamLeadUpsetException e) { | ||
throw new NoLeaveGrantedException("Leave not sanctioned.", e); | ||
} | ||
} | ||
|
||
private static void howIsTeamLead() throws TeamLeadUpsetException { | ||
try { | ||
howIsManager(); | ||
} catch (ManagerUpsetException e) { | ||
throw new TeamLeadUpsetException( | ||
"Team lead is not in good mood", e); | ||
} | ||
} | ||
|
||
private static void howIsManager() throws ManagerUpsetException { | ||
try { | ||
howIsGirlFriendOfManager(); | ||
} catch (GirlFriendOfManagerUpsetException e) { | ||
throw new ManagerUpsetException("Manager is in bad mood", e); | ||
} | ||
} | ||
|
||
private static void howIsGirlFriendOfManager() | ||
throws GirlFriendOfManagerUpsetException { | ||
throw new GirlFriendOfManagerUpsetException( | ||
"Girl friend of manager is in bad mood"); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core-java/src/main/java/com/baeldung/chainedexception/LogWithoutChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.baeldung.chainedexception; | ||
|
||
import com.baeldung.chainedexception.exceptions.GirlFriendOfManagerUpsetException; | ||
import com.baeldung.chainedexception.exceptions.ManagerUpsetException; | ||
import com.baeldung.chainedexception.exceptions.NoLeaveGrantedException; | ||
import com.baeldung.chainedexception.exceptions.TeamLeadUpsetException; | ||
|
||
public class LogWithoutChain { | ||
|
||
public static void main(String[] args) throws Exception { | ||
getLeave(); | ||
} | ||
|
||
private static void getLeave() throws NoLeaveGrantedException { | ||
try { | ||
howIsTeamLead(); | ||
} catch (TeamLeadUpsetException e) { | ||
e.printStackTrace(); | ||
throw new NoLeaveGrantedException("Leave not sanctioned."); | ||
} | ||
} | ||
|
||
private static void howIsTeamLead() throws TeamLeadUpsetException { | ||
try { | ||
howIsManager(); | ||
} catch (ManagerUpsetException e) { | ||
e.printStackTrace(); | ||
throw new TeamLeadUpsetException( | ||
"Team lead is not in good mood"); | ||
} | ||
} | ||
|
||
private static void howIsManager() throws ManagerUpsetException { | ||
try { | ||
howIsGirlFriendOfManager(); | ||
} catch (GirlFriendOfManagerUpsetException e) { | ||
e.printStackTrace(); | ||
throw new ManagerUpsetException("Manager is in bad mood"); | ||
} | ||
} | ||
|
||
private static void howIsGirlFriendOfManager() | ||
throws GirlFriendOfManagerUpsetException { | ||
throw new GirlFriendOfManagerUpsetException( | ||
"Girl friend of manager is in bad mood"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/com/baeldung/chainedexception/exceptions/GirlFriendOfManagerUpsetException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.baeldung.chainedexception.exceptions; | ||
|
||
public class GirlFriendOfManagerUpsetException extends Exception { | ||
|
||
public GirlFriendOfManagerUpsetException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public GirlFriendOfManagerUpsetException(String message) { | ||
super(message); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core-java/src/main/java/com/baeldung/chainedexception/exceptions/ManagerUpsetException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.baeldung.chainedexception.exceptions; | ||
|
||
public class ManagerUpsetException extends Exception { | ||
|
||
public ManagerUpsetException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ManagerUpsetException(String message) { | ||
super(message); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-java/src/main/java/com/baeldung/chainedexception/exceptions/NoLeaveGrantedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.baeldung.chainedexception.exceptions; | ||
|
||
public class NoLeaveGrantedException extends Exception { | ||
|
||
public NoLeaveGrantedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public NoLeaveGrantedException(String message) { | ||
super(message); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core-java/src/main/java/com/baeldung/chainedexception/exceptions/TeamLeadUpsetException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.baeldung.chainedexception.exceptions; | ||
|
||
public class TeamLeadUpsetException extends Exception { | ||
|
||
public TeamLeadUpsetException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public TeamLeadUpsetException(String message) { | ||
super(message); | ||
} | ||
} |