What is wrong with the following code?.
public class Main { public static void main(String[] args) throws A { try {/* w w w . j a va 2 s. com*/ f(); } finally { System.out.println("Done."); } catch (A e) { throw e; } } public static void f() throws B { throw new B(); } } class A extends Throwable {} class B extends A {}
Select the one correct answer.
main()
method must declare that it throws B.main()
method.main()
method must declare that it catches B rather than A.(b)
The only thing that is wrong with the code is the ordering of the catch and finally blocks.
If present, the finally block must always appear last in a try-catch-finally construct.