What is wrong with the following code?
class MyException extends Exception { } public class Main { public void foo() { try {/*from w ww .j a v a 2 s . c om*/ bar(); } finally { baz(); } catch (MyException e) {} } public void bar() throws MyException { throw new MyException(); } public void baz() throws RuntimeException { throw new RuntimeException(); } }
Select the one correct answer.
foo()
does not catch the exception generated by the method baz()
, it must declare the RuntimeException in a throws clause.(d)
A try block must be followed by at least one catch or finally block.
No catch blocks can follow a finally block.
Methods need not declare that they can throw Runtime Exceptions, as these are unchecked exceptions.