aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sendError and IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendError and IllegalStateException" Watch "sendError and IllegalStateException" New topic
Author

sendError and IllegalStateException

seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi
If I write something to the outputstream after calling sendError, what will happen ? The SCWCD Exam Study Kit says that this will cause IllegalStateException to be throws. But I have read somewhere else that the error would be just ignored. Which is correct ?
Thanks
Seema


Sun Certified Java Programmer<br />Sun Certified Web Component Developer<br />Sun Certified Business Component Developer
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
The specification says "If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to."
Which means, after this method is called, if anything is written to response, will be ignored (nowhere it is mentioned that IllegalStateException will be thrown)
HTH
-Varun


- Varun
seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi
Thanks for the info. Actually, I got this info from the SCWCD Study Kit by Hanumant Deshmukh. In the answer to question no: 2 of Chapter 7, it says " When the sendError() method is called, the response is assumed to be committed. If you write anything to the response after it is committed, IllegalStateException is thrown."
So they have given this as the correct answer to that question. Is this is a mistake in the book ?
Thanks
Seema
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
YES IT'S A MISTAKE
IMPORTANT concept( IS the response committed BEFORE CALLING sendError()or not?)

The answer is NO,(unless the buffer is full and flush() is called automatically) OR YOU FLUSH THE BUFFER EXPLICITLY)no exception will be thrown .As far as the statement AFTER calling sendError() is concerned ,if you write to the response then the data will be "SIMPLY IGNORED" and no exception is thrown.
"This method will have the side effect of committing the response ,if it has not already been committed and,TERMINATING it.
"for example if the buffer is half full,and you call sendEror() it will commit the response and TERMINATE it(SIDE EFFECT).
Once again don't bother about the data written to the response after sendError is called,it's simply ignored.The exception is thrown only if the response is committed before this method is called.

"Dont worry,be Happy"
Amer
[ May 13, 2003: Message edited by: Amer Khan ]

<i>Dare to dream - everything that exists today,was once a figment of someone's imagination, nobody says tomorrow can't be a figment of your today.</i>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendError and IllegalStateException