File tree Expand file tree Collapse file tree
src/main/java/com/baeldung/chainedexception Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616* .txt
1717/bin /
1818/temp
19+
20+ # IntelliJ specific
21+ .idea
22+ * .iml
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception ;
2+
3+ import com .baeldung .chainedexception .exceptions .GirlFriendOfManagerUpsetException ;
4+ import com .baeldung .chainedexception .exceptions .ManagerUpsetException ;
5+ import com .baeldung .chainedexception .exceptions .NoLeaveGrantedException ;
6+ import com .baeldung .chainedexception .exceptions .TeamLeadUpsetException ;
7+
8+ public class LogWithChain {
9+
10+ public static void main (String [] args ) throws Exception {
11+ getLeave ();
12+ }
13+
14+ private static void getLeave () throws NoLeaveGrantedException {
15+ try {
16+ howIsTeamLead ();
17+ } catch (TeamLeadUpsetException e ) {
18+ throw new NoLeaveGrantedException ("Leave not sanctioned." , e );
19+ }
20+ }
21+
22+ private static void howIsTeamLead () throws TeamLeadUpsetException {
23+ try {
24+ howIsManager ();
25+ } catch (ManagerUpsetException e ) {
26+ throw new TeamLeadUpsetException (
27+ "Team lead is not in good mood" , e );
28+ }
29+ }
30+
31+ private static void howIsManager () throws ManagerUpsetException {
32+ try {
33+ howIsGirlFriendOfManager ();
34+ } catch (GirlFriendOfManagerUpsetException e ) {
35+ throw new ManagerUpsetException ("Manager is in bad mood" , e );
36+ }
37+ }
38+
39+ private static void howIsGirlFriendOfManager ()
40+ throws GirlFriendOfManagerUpsetException {
41+ throw new GirlFriendOfManagerUpsetException (
42+ "Girl friend of manager is in bad mood" );
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception ;
2+
3+ import com .baeldung .chainedexception .exceptions .GirlFriendOfManagerUpsetException ;
4+ import com .baeldung .chainedexception .exceptions .ManagerUpsetException ;
5+ import com .baeldung .chainedexception .exceptions .NoLeaveGrantedException ;
6+ import com .baeldung .chainedexception .exceptions .TeamLeadUpsetException ;
7+
8+ public class LogWithoutChain {
9+
10+ public static void main (String [] args ) throws Exception {
11+ getLeave ();
12+ }
13+
14+ private static void getLeave () throws NoLeaveGrantedException {
15+ try {
16+ howIsTeamLead ();
17+ } catch (TeamLeadUpsetException e ) {
18+ e .printStackTrace ();
19+ throw new NoLeaveGrantedException ("Leave not sanctioned." );
20+ }
21+ }
22+
23+ private static void howIsTeamLead () throws TeamLeadUpsetException {
24+ try {
25+ howIsManager ();
26+ } catch (ManagerUpsetException e ) {
27+ e .printStackTrace ();
28+ throw new TeamLeadUpsetException (
29+ "Team lead is not in good mood" );
30+ }
31+ }
32+
33+ private static void howIsManager () throws ManagerUpsetException {
34+ try {
35+ howIsGirlFriendOfManager ();
36+ } catch (GirlFriendOfManagerUpsetException e ) {
37+ e .printStackTrace ();
38+ throw new ManagerUpsetException ("Manager is in bad mood" );
39+ }
40+ }
41+
42+ private static void howIsGirlFriendOfManager ()
43+ throws GirlFriendOfManagerUpsetException {
44+ throw new GirlFriendOfManagerUpsetException (
45+ "Girl friend of manager is in bad mood" );
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception .exceptions ;
2+
3+ public class GirlFriendOfManagerUpsetException extends Exception {
4+
5+ public GirlFriendOfManagerUpsetException (String message , Throwable cause ) {
6+ super (message , cause );
7+ }
8+
9+ public GirlFriendOfManagerUpsetException (String message ) {
10+ super (message );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception .exceptions ;
2+
3+ public class ManagerUpsetException extends Exception {
4+
5+ public ManagerUpsetException (String message , Throwable cause ) {
6+ super (message , cause );
7+ }
8+
9+ public ManagerUpsetException (String message ) {
10+ super (message );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception .exceptions ;
2+
3+ public class NoLeaveGrantedException extends Exception {
4+
5+ public NoLeaveGrantedException (String message , Throwable cause ) {
6+ super (message , cause );
7+ }
8+
9+ public NoLeaveGrantedException (String message ) {
10+ super (message );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .chainedexception .exceptions ;
2+
3+ public class TeamLeadUpsetException extends Exception {
4+
5+ public TeamLeadUpsetException (String message , Throwable cause ) {
6+ super (message , cause );
7+ }
8+
9+ public TeamLeadUpsetException (String message ) {
10+ super (message );
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments