Consider the following program:
import java.io.FileNotFoundException; import java.io.IOException; public class Main { public static void thrower() throws Exception { try {// ww w .j a va2 s .c o m throw new IOException(); } finally { throw new FileNotFoundException(); } } public static void main(String[] args) { try { thrower(); } catch (Throwable throwable) { System.out.println(throwable); } } }
When executed, this program prints which one of the following?
B.
if both the try block and finally block throw exceptions, the exception thrown from the try block will be ignored.
hence, the method thrower()
throws a FileNotFoundException.
the dynamic type of the variable throwable is FileNotFoundException, so the program prints that type name.