Consider the following program:
import java.io.*; public class Main { public static void thrower() throws Exception { try { throw new IOException(); } finally { throw new FileNotFoundException(); }/*from w ww . j av a2s. c om*/ } public static void main(String []args) { try { thrower(); } catch(Throwable throwable) { System.out.println(throwable); } } }
When executed, this program prints 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.