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 ?
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With