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
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
B. According to code I’ve posted in question 50
A
look at multi catch
A..Compilatnd as FileNotFoundException is already caught by an alternative IOException.
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;
}
A FileNotFoundException sub classed IOException and has been caught