给定以下Java代码,其中包含一个自定义异常类`CustomException`和两个方法`methodA`和`methodB`,`methodA`调用`methodB`,且`methodB`可能抛出`CustomException`。若在`methodA`中捕获了`CustomException`并打印了错误信息,则`main`方法中调用`methodA`后,下列哪种描述正确? ```java class CustomException extends Exception { public CustomException(String message) { super(message); } } public class ExceptionTest { public static void methodB() throws CustomException { throw new CustomException("Exception in methodB"); } public static void methodA() { try { methodB(); } catch (CustomException e) { System.err.println("Caught in methodA: " + e.getMessage()); } } public static void main(String[] args) { methodA(); System.out.println("Finished in main"); } } ```
答案解析
在`methodA`中,`try-catch`块成功捕获了`methodB`抛出的`CustomException`,并在错误流中打印了异常信息。由于异常在`methodA`中被处理,`methodA`正常返回。随后,`main`方法会继续执行,打印“Finished in main”。选项A错误,因为异常被捕获,程序不会终止;选项C错误,异常不会传递到main方法;选项D错误,main方法后续代码会执行。
正确答案:B