Filenotfound crash exception

Thus, they say that they will catch only exceptions that you cannot predict or are exceptional.

So, for example, IOExceptions instead of FileNotFoundException (since this single case can be handled with a simple file check, avoiding the use of exceptions as flow control).

This is my understanding of the topic, correct me if I am wrong.

However, this begs the question ... why are there exceptions like FileNotFoundException?

thank

+3
source share
3 answers

You must catch exceptions that you can handle. Your first sentence is a bit wrong, and may be the cause of your confusion.

" , , , ".

" , , , ".

, FileNotFoundException, . , IOException , , ( ?) .

+2

, , , , . , .

+2

You must distinguish between best practices and absolute requirements. It is recommended that you first check the file before trying to access it. However, this cannot be realized. Since this is an absolute requirement that a file exist before it is accessed, the infrastructure will throw an exception to enforce this condition.

In an ideal world, there would be no exceptions, because there would be no errors, and all programs and networks (and users!) Would be absolutely perfect.

0
source

All Articles