Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

QUESTION on ERROR HANDLING

 
Julia Julia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I was reading the Manning's SCWCD Study Kit , and particularly confused on the NOTE regarding error handling on page 103 :

"if an error handler is invoked as a result of either the setStatus() or the sendError() method, javax.servlet.error.exception and javax.servlet.error.exception_type are set to null. Similarly, if an error handler is invoked as a result of an exception, javax.servlet.error.code is set to null"

However,

when I wrote a test program that throws an exception , I was able to retrieve BOTH error code and exception type. Here's the output :

ERROR CODE : 500 EXCEPTION TYPE : class java.sql.SQLException

and here's my code :

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

PrintWriter pw = resp.getWriter();
pw.print("Print something first ");

throw new ServletException("SQLException inside",new SQLException());
}

here's my JSP error page :

<BODY>
I AM THE INTERNAL SERVER ERROR PAGE

THE EXCEPTION THAT I RECEIVE WAS:

ERROR CODE :
<%= request.getAttribute("javax.servlet.error.status_code") %>


EXCEPTION TYPE :

<%= request.getAttribute("javax.servlet.error.exception_type") %>

</BODY>

here's the mapping :

<error-page>
<error-code>500</error-code>
<location>/Error1JSP.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/Error1JSP.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/Error1JSP.jsp</location>
</error-page>


Can someone clarify or correct ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic