Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendError and IllegalStateException

 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
seema mani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic