users@glassfish.java.net

Re: servlet: try ... finally {out.close();} <-bad idea?

From: Hassan Schroeder <hassan.schroeder_at_gmail.com>
Date: Sun, 30 May 2010 13:29:37 -0700

On Sun, May 30, 2010 at 11:15 AM, Mark Mielke <mark_at_mark.mielke.cc> wrote:

> However, I don't think this answers the question. It avoids the question
> entirely.

I'd say it "reframes the issue", the *original* question being about serving
a page with a 200 OK header when there's actually been an error, and
there's an open PrintWriter instance.

> There are times when using the PrintWriter yourself makes sense.

I doubt it, but for the sake of discussion ... :-)

> There is always the possibility of an exception being raised. The "try ...
> finally { out.close(); }" seems like a good idea

Of course it is, or at least I can't imagine a reason to leave it open --
but it's *not* going to change the fact that the response has been
committed, and the error in your view code will be ugly and out of
sync with the response header.

-- 
Hassan Schroeder ------------------------ hassan.schroeder_at_gmail.com
twitter: @hassan