Have you ever seen a Java File close() throw an exception?

前端 未结 8 762
野性不改
野性不改 2020-12-31 00:10

Has anyone ever seen an exception thrown when calling close method on any closable object?

相关标签:
8条回答
  • 2020-12-31 00:41

    I guess you could try to force this by unplugging the disk your file is on. But on any Closable? I think it would be easy to get something that uses a socket to throw an exception upon closing.

    0 讨论(0)
  • 2020-12-31 00:43

    Not in terms of file-io, but in terms of sockets the close will raise IOException when the other side has aborted the connection. For example, when you fire a HTTP request on a (large) webpage and then immediately navigate away by clicking another link on the webpage (while it isn't finished loading), then the server side will get an IOException (or a subclass like ClientAbortException in Tomcat servers and clones) when the outputstream of the HTTP response is to be flushed/closed.

    0 讨论(0)
提交回复
热议问题