What is the result, if the file myfile.txt does not exist?

Given the code fragment: What is the result, if the file myfile.txt does not exist?

Given the code fragment: What is the result, if the file myfile.txt does not exist?

A.
Compilation fails

B.
A runtime exception is thrown at line 4

C.
A runtime exception is thrown at line 7

D.
Creates a new file and prints no output



Leave a Reply 5

Your email address will not be published. Required fields are marked *


duff

duff

B. According to code I’ve posted in question 50

Babak

Babak

A
look at multi catch

Sanjukta

Sanjukta

A..Compilatnd as FileNotFoundException is already caught by an alternative IOException.

nk

nk

Consider the following example, which contains duplicate code in each of the catch blocks:

catch (IOException ex) {
logger.log(ex);
throw ex;
catch (SQLException ex) {
logger.log(ex);
throw ex;
}
In releases prior to Java SE 7, it is difficult to create a common method to eliminate the duplicated code because the variable ex has different types.

The following example, which is valid in Java SE 7 and later, eliminates the duplicated code:

catch (IOException|SQLException ex) {
logger.log(ex);
throw ex;
}

leo yu

leo yu

A FileNotFoundException sub classed IOException and has been caught