@@ -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 }
0 commit comments