• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Chapter 9, review question 7 - OCP Java SE 8 Programmer II - Jeanne Boyarsky & Scott Selikoff

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am referring to the book "OCP Oracle Certified Professional Java SE 8 Programmer II Study Guide - Jeanne Boyarsky & Scott Selikoff.

Chapter 9, review question 7 has following code.
Answer to this question mentioned as option "F" - It compiles but throws an exception at runtime.

Don't we need to surround isSameFile & createDirectory methods with try & catch as these methods throw IOException.
I believe this code will fail to compile. Please clarify.


Thanks
 
Marshal
Posts: 6851
470
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't have the book next to me at the moment, but certification books quite often don't write code to cover full context, which is right, because try{} catch{} are handling parts, while the question I presume is asking different thing.

However, if you don't see the try{} catch{} in this snippet, that doesn't mean that author did not place them hypothetically somewhere around the larger chunk of code which you obviously don't see in those 3 lines.

So I wouldn't call it a mistake. In the same way you could say Paths class isn't imported as import statement isn't specified, so code wouldn't compile either.
 
Liutauras Vilda
Marshal
Posts: 6851
470
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!