How to properly handle an IOException from close()

前端 未结 9 1567
滥情空心
滥情空心 2021-02-05 08:14

The Java I/O classes java.io.Reader, java.io.Writer, java.io.InputStream, java.io.OutpuStream and their various subclasses al

9条回答
  •  日久生厌
    2021-02-05 08:46

    Log it.

    You can't really do anything about it (for example write some code that recovers from the error), but its generally worth letting somebody know about it.

    Edit:
    After further investigation and reading the other comments, I'd say that if you do want to handle it then you're going to have to know details of the implementation. Conversely you probably need to know details of the implementation to decide whether you need to handle it.

    Realistically though, I can't think of any examples of streams where the reading or writing would work correctly without throwing an exception, but the closing would.

提交回复
热议问题