在 Java 中,有一些类型的异常需要 throws 语句:
public void myMethod() throws IOException {
throw new IOException("Error!");
}
而其他人则没有:
public void myOtherMethod() {
throw new IllegalArgumentException("Error!");
}
public void myThirdMethod() {
throw new Error("Error!");
}
throws
第一种方法不会在没有语句的情况下编译。
确定Exception
/是否Error
需要throws
声明的标准是什么?