In one of my Java application's code, I have a try-catch-finally
block in which the try
block creates some input and output streams and if something goes wrong I close any earlier opened streams in finally
.
finally
{
if(inputStream != null)
inputStream.close();
if(outputStream != null)
outputStream.close();
}
But the <stream>.close()
line in Eclipse shows error that "Unhandled exception IOException" in the code for this line and shows that the solution is to include another try/catch
in the finally
block which would seem to be bad as a programming practice and I don't want in finally block.
My question is: is it possible to remove this error in Eclipse and use try/catch
only when I need it instead of eclipse telling me to do the try/catch
add. (Since I am already trying to avoid exception by replacing try/catch
with if/else
as possible).