Which expression, when inserted into the blank in the following class, allows the code to compile?
package mypkg;/*from ww w . j av a 2 s.co m*/ public class Main { class Login implements AutoCloseable { @Override public void close() throws Exception1 {} } class Exception1 extends Exception { public Exception1(String message) {} } public static void main(String[] notes) throws Throwable { try (Login p = null) { throw new Exception(); } catch (Exception e) { } catch ( ) { } } }
A.
The try-catch block already catches Exception, so the correct answer would be the one that is not a subclass of Exception.
In this case, Error extends Throwable and is the only choice that allows the code to compile.
Because IllegalStateException and Exception1 both inherit from Exception, Options B and C, respectively, are incorrect.
Finally, Option D is incorrect because there is an answer choice that allows the code to compile.