ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: Purpose of FileUtils.close(...)
Date Tue, 04 Jan 2005 15:32:13 GMT

(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


Mime
View raw message