Here's the question:
Given:
And the following three possible changes:
C1. Declare that main() throws an Exception.
C2. Declare that Ping.getInt() throws an Exception.
C3. Wrap the invocation of getInt() in a try / catch block.
Which change(s) allow the code to compile? (Choose all that apply.)
A) Just C1 is sufficient.
B) Just C2 is sufficient.
C) Just C3 is sufficient.
D) Both C1 and C2 are required.
E) Both C1 and C3 are required.
F) Both C2 and C3 are required.
All three changes are required.
The given answer is A and C. However I have a problem. The K&B itself states that the main method cannot declare an exception in its signature because it cannot pass the exception to another method because there is no method lower down the call stack. Here are the exact words from K&B:
Because it's a checked exception, the checkFood() method must declare it, and the main() method must handle it (using a try/catch). Do not have main() declare the exception, because if main() ducks the exception, who else is back there to catch it?
So how can C1 which makes main declare exception in its signature be correct?