• Post Reply Bookmark Topic Watch Topic
  • New Topic

Errata - OCP Java SE 8 Study Guide - Page 497 #3  RSS feed

 
Thomas Roth
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think all answers are wrong, because the code does not compile, it has an unhandled IO-Exception with Files.newdirectoryStream(Path)
At least in my IDE, so i think all of possible answers are wrong.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Thomas Roth
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is similar to some other erratas i found.

Answer must be B,D because there is also an unhandled IO-Exception from Files.readAttributes() in line 2 of the code snippet.
With this handled, the answer would be only D like it tells.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Oracle has a disclaimer that you should assume the necessary context:
Code fragments: A code fragment is a small section of source code that is presented without its context. Assume that all necessary supporting code exists and that the supporting environment fully supports the correct compilation and execution of the code shown and its omitted environment.


This means if the code isn't in a method, you can assume it declares any checked exceptions. You will see this technique on the real exam too so glad it came up here!
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Thomas Roth
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code snippet will not compile because "Files.deleteIfExists(path) has an unhandled IO-exception.
So the correct answer would be F, NOT B,C
 
Thomas Roth
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:No. Oracle has a disclaimer that you should assume the necessary context:
Code fragments: A code fragment is a small section of source code that is presented without its context. Assume that all necessary supporting code exists and that the supporting environment fully supports the correct compilation and execution of the code shown and its omitted environment.


This means if the code isn't in a method, you can assume it declares any checked exceptions. You will see this technique on the real exam too so glad it came up here!


Puh, thank you very much Jeanne, i would have missed that in the exam. Really glad it came up here too
So, if no method is shown, all exception handling is done. Good to know! Thank you.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas Roth wrote:Puh, thank you very much Jeanne, i would have missed that in the exam. Really glad it came up here too
So, if no method is shown, all exception handling is done. Good to know! Thank you.

Correct. And I'm really glad you asked so you don't lose points for this on the real exam!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!