【发布时间】:2018-02-02 10:55:29
【问题描述】:
为什么当我在方法内抛出 RuntimeException 时我没有收到任何错误,但当我在方法内抛出 IOException 时我还需要从方法中抛出异常?
public void throwException() {
throw new RuntimeException();
}
这很好用。当我抛出 IndexOutOfBoundsException、NullPointerException 和 InputMismatchException 等等时,也会发生同样的事情。
但是当我抛出IOException时,该方法也必须抛出IOException:
public void throwException() throws IOException {
throw new IOException();
}
【问题讨论】: