【发布时间】:2017-01-29 23:28:49
【问题描述】:
我正在使用类生成器的这种方法:
public void executeAction(String s) throws MyException {
if (s.equals("exception"))
throw new MyException("Error, exception", this.getClass().getName());
}
public void close() {
System.out.println("Closed");
}
我已将它们与这段代码一起使用:
public void execute() throws MyException
Generator generator = new Generator();
try {
String string = "exception";
generator.executeAction(string);
} finally {
generator.close();
}
}
在 main 我处理了异常:
try {
manager.execute();
} catch (MyException e) {
System.err.println(e.toString());
}
}
在 main 我可以抓住它。这是正常行为吗?
【问题讨论】:
-
您为什么希望抑制该异常?
-
抱歉,我更正了问题
-
最终是否生效异常。所以如果一个异常被抛出并且没有被捕获不会影响finally
标签: java exception exception-handling try-catch-finally try-with-resources