• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about try catch exception handling re: FileNotFoundException

 
james falk
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

so I am working on my first program using try catch exceptions, and here's my problem:



The compiler is giving me an error that says the catch block is unreachable. Not sure I understand why, because if a file isn't found, wouldn't the exception be thrown? Thanks in advance for any help you can offer! I did import the java.io.FileNotFoundException and
java.io.IOException if that helps....
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a File object it doesn't actually do anything other than create the object. It doesn't even check the file system. Only once you try to open the file, using FileInputStream, FileReader or other similar ways, will a FileNotFountException potentially be thrown.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!