【发布时间】:2013-08-31 20:50:10
【问题描述】:
假设如下代码:
public static void somMethod() throws IOException {
try {
// some code that can throw an IOException and no other checked exceptions
} catch (IOException e) {
// some stuff here -- no exception thrown in this block
}
}
someMethod 抛出 IOException,并且没有其他检查异常, 并自行处理该异常。
究竟是什么
throws IOException
在它的声明中是带进来的? 据我所知,它使这些方法成为可能 调用 someMethod() 自己处理 IOException。
这里还有其他事情吗?
【问题讨论】:
-
如果
catch块重新抛出异常,则throws IOException是调用该方法的任何代码所必需的。 -
不,捕获数据。很清楚。
-
..但是谢谢。
-
我希望我能回答这个问题,但我无法理解你的问题。您能否改写或添加更多细节?谢谢。
-
@Nayuki Minase 宁愿要求验证——而不是 Q 本身。看起来很简单,背后没有任何东西。
标签: java exception-handling throws checked-exceptions