Do I need to handle or ignore the IOException raised by the OutputStream close () function?

In the following code, the close function for outPutStream throws an IOException, which I must catch. My question is do I need to handle this? Since I work with mobile devices, I want to make sure that I free up all the resources that I use, or whether I can safely ignore the exception.

//...
OutputStream output = null;
try {
     output = connection.getOutputStream();
     output.write(query.getBytes(charset));
} finally {
     if (output != null) try { 
        output.close(); 
     } catch (IOException e) {
        // Do i need to do something here ?
     }
}
+5
source share
4 answers

If closing does not work, what can you do?

The only thing you can do is just to throw an exception, and since @mprabhat suggested you set the link to null to speed up the GC.

+7
source

java , IOException, , .

, OutputStream null .

+3

. , , . .

0

Java Joshua Bloch , . , , , , .

0

All Articles