[英]throws statement for handled exceptions — Java
假设以下代码:
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块没有抛出IOException
,则不需要在方法签名中throws IOException
部分。 而且,每次调用someMethod()
,都必须为可能的异常提供一个实际上永远不会发生的catch
块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.