Given the code fragment:
public void processFile() throws IOException, ClassNotFoundException {
try (FileReader fr = new FileReader ("logfilesrc.txt");
FileWriter fw = new FileWriter ("logfiledest.txt")) {
Class c = Class.forName ("java.lang.JString");
}
If exception occur when closing the FileWriter object and when retrieving the JString class object,
which exception object is thrown to the caller of the processFile method?
A.
java.io.IOException
B.
java.lang.Exception
C.
java.lang.ClassNotException
D.
java.lang.NoSuchClassException
Explanation:
C ClassNotFoundException
A is suppressed exceptions
java.lang.ClassNotFoundException: java.lang.JString
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at Snippet.processFile(Snippet.java:20)
at Snippet.main(Snippet.java:9)
Suppressed: java.io.IOException: Something wrong
at FileReader.close(FileReader.java:20)
at Snippet.processFile(Snippet.java:21)
… 1 more