You have the following program in a file called that reads the contents of a file called and prints the number of lines contained within it.
import .*;
import .List;
class ExamPrep {
public static void main(String[] args) {
Path path = Path.of(" ");
List lines = Files.readAllLines(path);
System.out.println( ());
}
}
When you compile this program using javac , you get the following error: : error: unreported exception IOException; must be caught or declared to be thrown
List lines = Files.readAllLines(path);
^
1 error You have decided to add a try/catch block to fix this error.
Which code block below shows a syntactically correct use of a try/catch block and will compile without error?
A. public static void main(String[] args) {
Path path = Path.of(" ");
try {
List lines = Files.readAllLines(path);
} catch {
System.out.println( .IOException.getMessage());
}
System.out.println( ());
}
B. public static void main(String[] args) {
Path path = Path.of(" ");
try {
List lines = Files.readAllLines(path);
System.out.println( ());
} catch {
System.out.println( .IOException.getMessage());
}
}
C. public static void main(String[] args) {
Path path = Path.of(" ");
try {
List lines = Files.readAllLines(path);
} catch ( .IOException e) {
System.out.println(e.getMessage());
}
System.out.println( ());
}
D. public static void main(String[] args) {
Path path = Path.of(" ");
try {
List lines = Files.readAllLines(path);
System.out.println( ());
} catch ( .IOException e) {
System.out.println(e.getMessage());
}
}