-
611 votesanswersviews
Java:已检查vs未经检查的异常说明
我已经在StackOverFlow上阅读了有关已检查和未经检查的异常的多个帖子 . 老实说,我还是不太确定如何正确使用它们 . Joshua Bloch在“Effective Java”中说过 对可恢复条件使用已检查的异常,对编程错误使用运行时异常(第2版中的第58项) 让我们看看我是否正确理解了这一点 . 以下是我对已检查异常的理解: try{ String userInput = ... -
33 votesanswersviews
为什么捕获检查的异常允许不抛出异常的代码?
在Java中,抛出 checked 异常(Exception或其子类型 - IOException,InterruptedException等)的方法必须声明 throws 语句: public abstract int read() throws IOException; 不声明 throws 语句 can't 抛出已检查异常的方法 . public int read() { // does...