Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on K& B chapter 5.

 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

three possible changes
C1. Declare the main() throws an Exception
C2. Declare the Ping.getInt() throws an Exception
C3. Wrap the invocation of getInt() in 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
G. All three changes are required

Answer was A and C

My question is why B is considered incorrect when the question states that choose all that apply for successfully compilation.
Also the answer in the book states that B is not ncessary so confused..

Please let me know the reason.

thanks a lot!
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Maybe you need to try to compile the program and see which options are required to make successful compile.

However in main method you are invoking(at compile time) a method that might throw a checked Exception.

Either you need to declare that the calling method which is 'main' to throw the Exception, or wrap the method call getInt() in a try/catch block.
 
Matthias Wendel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because

makes the compiler complain that there is an

in line 4.
Regards,
Matthias
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic