【发布时间】:2013-07-17 13:19:36
【问题描述】:
在 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 语句的标准是什么?
【问题讨论】:
-
由于缺乏研究而投反对票。这是 Java 101。
标签: java exception exception-handling error-handling throws