Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why the File constructor doesn't throw exception?

802930Mar 18 2011 — edited Mar 18 2011
Hi,

I was wondering why the File class constructor doesn't need a checked exception in case the file path would be wrong or the file doesn't exist.

For example if we use a Scanner to read from a file, the Scanner constructor does throws FileNotFoundException.
Why do Java only checks it there and not when the File object is created? What is behind this?
File inFile = new File("c:/myfile.txt"); 
Scanner sc = new Scanner(inFile);  // can throw FileNotFoundException
Thanks in advance for any comments.
This post has been answered by 796440 on Mar 18 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 15 2011
Added on Mar 18 2011
3 comments
759 views