File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,31 @@ public static void main(String[] args) {
2525 System .err .println (e .getMessage ());
2626 }
2727
28+ // alternative multiple catch:
29+ try {
30+ e1 .setSalaryInEuro (55000 );
31+ e2 .setSalaryInEuro (77000 );
32+ e3 .setSalaryInEuro (45000 );
33+ } catch (SalaryDecreaseException e ) {
34+ System .out .println ("Das neue Gehalt muss hoeher sein als das bisherige" );
35+ } catch (SalaryIncreaseTooHighException e ) {
36+ System .out .println ("Das neue Gehalt darf maximal 10% ueber dem bisherigen Gehalt liegen" );
37+ }
38+
39+ // alternative instance of
40+ try {
41+ e1 .setSalaryInEuro (55000 );
42+ e2 .setSalaryInEuro (77000 );
43+ e3 .setSalaryInEuro (45000 );
44+ } catch (Exception e ) {
45+ if (e instanceof SalaryDecreaseException ) {
46+ System .out .println ("Das neue Gehalt muss hoeher sein als das bisherige" );
47+ }
48+ if (e instanceof SalaryIncreaseTooHighException ) {
49+ System .out .println ("Das neue Gehalt darf maximal 10% ueber dem bisherigen Gehalt liegen" );
50+ }
51+ }
52+
2853 System .out .println (company .toString ());
2954 }
3055}
Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ public class SalaryDecreaseException extends Exception {
22
33 public SalaryDecreaseException () {
44 super ("Das neue Gehalt muss hoeher sein als das bisherige" );
5+ // alternativ: super();
56 }
67}
Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ public class SalaryIncreaseTooHighException extends Exception {
22
33 public SalaryIncreaseTooHighException () {
44 super ("Das neue Gehalt darf maximal 10% ueber dem bisherigen Gehalt liegen" );
5+ // alternativ: super();
56 }
67}
You can’t perform that action at this time.
0 commit comments