Assuming that getNameFromDBSomeHow() returns null, which of the following statements regarding this code are correct? (Select one) a It will throw an InvalidStateException while serving a request. b It will throw a ServletException while serving a request. c It will throw a NullPointerException while serving a request. d It will throw an IllegalStateException while serving a request. e It will not throw an exception.
Anwer given is : D. But as per the spec after SendRedirect() any out will be ignored as its content is in buffer.No exception will occur. My Answer is: E and i run this exam on my server and my answer is right.
Now biggest question is what to do with similar kind of questions in exam ?
You're right. Since the output stream is not committed, there is no way an ISE will ever be thrown.
An ISE is thrown when the stream is committed before calling sendError(). E.g.:
Note that neither the errorpage, nor the exception reaches the client. The browser will show "hello", and the ISE is written in a log file on the server.
If you do this:
the error page shows up and no ISE is thrown at all.
Surprisingly, if one does this:
an error page shows up with an ISE (code 500)!!! One should expect that - the 405-error page is sent to the client - an ISE is thrown on the second sendError() - a 500-error page doesn't reach the client, just like in my first code snippet.
Does anyone have a logical explanation for this?
Originally posted by gopal venu: [CODE] ... Now biggest question is what to do with similar kind of questions in exam ?
The real exam doesn't show you the answers, so you won't have that problem [ June 18, 2008: Message edited by: Jan Sterk ]
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
Joined: Jun 14, 2008
"Verify your errata using the appropriate spec, and use the answer provided by the spec since that is what the exam is based on."
This was a reference on how to deal with the incorrect answers in books and mock exams. Because it has received a little more scrutiny, you are less likely to encounter such questions on the real (Sun sponsored) exam.