Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do i need to handle or ignore the IOException fired by OutputStream close() function?

In the following code the close function for outPutStream throw an IOException exception that I should catch. My question is do I need to handle it? Since I'm working with mobile devices and I want to make sure that I free all resources that I use, or could I 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 ?
     }
}
like image 215
Jimmy Avatar asked Dec 14 '11 15:12

Jimmy


1 Answers

If the close doesn't work, what can you do?

The only thing you can do is just log the exception, and as @mprabhat has suggested you can set the reference to null to speed up GC.

like image 103
stivlo Avatar answered Sep 30 '22 13:09

stivlo