Skip to content

Commit bf098f9

Browse files
committed
fix
1 parent 12b7728 commit bf098f9

7 files changed

Lines changed: 39 additions & 23 deletions

File tree

‎exceptions/BodyException.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static void main(String[] args) {
1515
Third t = new Third();
1616
new SecondExcept();
1717
System.out.println("End of body");
18-
} catch(CE e) {
18+
}
19+
catch(CE e) {
1920
System.out.println("Caught: " + e);
2021
}
2122
}

‎exceptions/CloseExceptions.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public static void main(String[] args) {
3232
Second s = new Second()
3333
) {
3434
System.out.println("In body");
35-
} catch(CloseException e) {
35+
}
36+
catch(CloseException e) {
3637
System.out.println("Caught: " + e);
3738
}
3839
}

‎exceptions/Human.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public static void main(String[] args) {
1212
// Catch the exact type:
1313
try {
1414
throw new Sneeze();
15-
} catch(Sneeze s) {
15+
} catch(Sneeze s) { // Annoyance
1616
System.out.println("Caught Sneeze");
17-
} catch(Annoyance a) {
17+
} catch(Annoyance a) { // Sneeze
1818
System.out.println("Caught Annoyance");
1919
}
2020
// Catch the base type:

‎exceptions/InputFile2.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Stream<String> getLines() throws IOException {
1717
}
1818
public static void
1919
main(String[] args) throws IOException {
20-
new InputFile2("InputFile2.java").getLines()
21-
.skip(15)
22-
.limit(1)
20+
new InputFile2("/Users/zss/Projects/OnJava8-Examples/exceptions/InputFile2.java").getLines()
21+
.skip(14)
22+
.limit(2)
2323
.forEach(System.out::println);
2424
}
2525
}

‎exceptions/LostMessage.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ public static void main(String[] args) {
3131
} finally {
3232
lm.dispose();
3333
}
34-
} catch(VeryImportantException |
35-
HoHumException e) {
34+
} catch(
35+
VeryImportantException
36+
|
37+
HoHumException e
38+
) {
3639
System.out.println(e);
3740
}
3841
}

‎exceptions/StormyInning.java‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,29 @@ class StormyInning extends Inning implements Storm {
3333
// OK to add new exceptions for constructors, but you
3434
// must deal with the base constructor exceptions:
3535
public StormyInning()
36-
throws RainedOut, BaseballException {}
36+
throws
37+
RainedOut
38+
,
39+
BaseballException
40+
{
41+
42+
}
3743
public StormyInning(String s)
38-
throws BaseballException {}
44+
throws BaseballException
45+
{}
3946
// Regular methods must conform to base class:
40-
//- void walk() throws PopFoul {} //Compile error
47+
// void walk() throws PopFoul {} //Compile error
4148
// Interface CANNOT add exceptions to existing
4249
// methods from the base class:
43-
//- public void event() throws RainedOut {}
50+
// public void event() throws RainedOut {}
4451
// If the method doesn't already exist in the
4552
// base class, the exception is OK:
4653
@Override public void rainHard() throws RainedOut {}
4754
// You can choose to not throw any exceptions,
4855
// even if the base version does:
4956
@Override public void event() {}
5057
// Overridden methods can throw inherited exceptions:
51-
@Override public void atBat() throws PopFoul {}
58+
@Override public void atBat() throws PopFoul{}
5259
public static void main(String[] args) {
5360
try {
5461
StormyInning si = new StormyInning();
@@ -67,13 +74,17 @@ public static void main(String[] args) {
6774
i.atBat();
6875
// You must catch the exceptions from the
6976
// base-class version of the method:
70-
} catch(Strike e) {
77+
}
78+
catch(Strike e) {
7179
System.out.println("Strike");
72-
} catch(Foul e) {
80+
}
81+
catch(Foul e) {
7382
System.out.println("Foul");
74-
} catch(RainedOut e) {
83+
}
84+
catch(RainedOut e) {
7585
System.out.println("Rained out");
76-
} catch(BaseballException e) {
86+
}
87+
catch(BaseballException e) {
7788
System.out.println("Generic baseball exception");
7889
}
7990
}

‎exceptions/TryAnything.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//class Anything {}
88
//
99
//public class TryAnything {
10-
// public static void main(String[] args) {
11-
// try(
12-
// Anything a = new Anything()
13-
// ) {
14-
// }
10+
//// public static void main(String[] args) {
11+
//// try(
12+
////// Anything a = new Anything()
13+
//// ) {
14+
//// }
1515
// }
1616
//}

0 commit comments

Comments
 (0)