You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Steve Loughran <st...@apache.org> on 2005/01/04 16:32:13 UTC
Re: Purpose of FileUtils.close(...)
(I'm just catching up on 3 weeks worth of mail, sorry for joining in late)
>> So what exactly *is* the intention of this method? [...]
We wrote it because we were repeating the same code throughout exception
handling logic: closing files and swallowing exceptions.
try {
file=myfile.open();
...
file.close();
} finally {
if(file!=null) {
try { file.close(); } catch(IOException ioe) { }
}
Now, if you eliminate the file.close() from the main clause, the finally
will do the work for you, but it will swallow any exceptions. Which was
not the original intent, but something we clearly have enabled.
Perhaps we should always log trouble on the way out -one advantage of
having the code in one place is that we do have only one point to
instrument.
-steve
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org