The Artima Developer Community
Sponsored Link

finally and close

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

finally and close

Posted by Dan Lohman on 18 Sep 1998, 1:39 PM

Should I call flush prior to the close in the finally clause?
What happens if flush throws exception?
Should I move the flush into the try block?
Any suggestions.

try {
fos = new FileOutputStream(prefix + "DMC.ser");
oos = new ObjectOutputStream(fos);
Container container = this.getContainer();
os.writeObject(container);
} finally {
if(oos!=null) {
oos.flush();
oos.close();
}
}

or
try {
fos = new FileOutputStream(prefix + "DMC.ser");
oos = new ObjectOutputStream(fos);
Container container = this.getContainer();
os.writeObject(container);
oos.flush();
} finally {
if(oos!=null) {
oos.close();
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us