【发布时间】:2014-11-15 13:48:01
【问题描述】:
我正在为try-with-resources 阅读此link,它说:
Closeable接口的close方法抛出IOException类型的异常,而AutoCloseable接口的close方法抛出Exception类型的异常。
但是为什么呢? AutoCloseable 的关闭方法也可能抛出 IOException 是否有任何示例支持 AutoCloseable 的关闭方法必须抛出 Exception 类型的异常
【问题讨论】:
-
我认为这对语言制造商来说只是一个糟糕的决定。它要求您在使用 try-with-resources 的任何地方捕获通用异常。
标签: java try-catch try-with-resources