Consider the following program:
public class Main { public static void foo() { try { throw new ArrayIndexOutOfBoundsException(); } catch(ArrayIndexOutOfBoundsException oob) { throw new Exception(oob); }/*from w w w . j av a 2s. c o m*/ } public static void main(String []args) { try { foo(); } catch(Exception re) { System.out.println(re.getCause()); } } }
Which one of the following options correctly describes the behavior of this program?
D.
The foo()
method catches ArrayIndexOutOfBoundsException and chains it to an Exception object.
However, since Exception is a checked exception, it must be declared in the throws clause of foo()
.