Odi fetches me up about exception handling.
Instead of this:
finallyDo this:
{
try
{
if (fos != null)
{
fos.close();
}
if (osw != null)
{
osw.close();
}
if (theFile != null)
{
theFile.close();
}
}
catch (IOException ignored)
{
log4jLogger.error(ignored);
}
}
finallyThat way, if an exception is thrown early on, your code will continue trying to close the other resources.
{
close(fos);
close(osw);
close(theFile);
}
private void close(Closeable closeMe)
{
if (closeMe != null)
{
try
{
closeMe.close();
}
catch(IOException ignore)
{
log4jLogger.error(ignore);
}
}
}
No comments:
Post a Comment