• Post Reply Bookmark Topic Watch Topic
  • New Topic

pageContext.getException() always null  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a rather strange problem with handling an exception within a custom
jsp tag.

The problem is, that pageContext.getException() always returns null.
This is the case within the tag's code, but also witin a Scriptlet inside
the JSP.
However, the variable 'exception' itself is properly set.

My error.jsp looks like this:
<%@page isErrorPage="true" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

System.out.println("Exception = " + exception);
System.out.println("exPage = " + pageContext.getException());

<H1>Error occured</H1>

The tag class has code like this:

private Exception getTerribleException() {

if (pageContext.getException() == null) {
System.out.println("pageContext has null exception");
return null;

Well, the output is as mentioned above: only the variable 'exception' within
the JSP can be successfully accessed. Retrieving the exception from the
pageContext always returns null.

Exception = javax.servlet.ServletException: This is my self thrown
exPage = null
pageContext has null exception

The error page is comming up by tomcat through the <error-page>
entry in web.xml:


As far as I know, for all error pages (<%@page isErrorPage="true" %> ,
the counterpart for the implicit variable 'exception' of a JSP is

However, something seems to go wrong.
I'm using JBoss 3.2.26 with integrated Tomcat. I also tried tomcat
standalone (5.0.18), same result.

Help greatly appreciated,
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the pageContext.getException() work on my Sun web server very well. as following, I can get error information on my web page when an exception occur.

<TITLE>Error Page</TITLE>
<%@ page isErrorPage="true" %>
<%@ page import="java.io.*" %>
Error Computing Speed</TABLE>
ComputeSpeed.jsp reported the following error:
<I><%= exception %></I>. This problem occurred in the
following place:
<% out.println("exPage=" + pageContext.getException()); %>
Konrad Bernstein
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me like a pure Tomcat-issue.
Downloaded and tested a couple of TC versions (5.0.28, 5.0.30 beta).
Same result: always returns null.

I then built Tomcat on my own (via Tomcat-5.0-Build-Script and everything worked fine there.

Looking at the source of class PageContextImpl made clear, that
the version has changed. The new implementation of method getException()
now uses instead of

This comes down to returning the request attribute
"javax.servlet.error.exception" instead of

So, if you use code like

instead of

you should be fine.

However, looks like a TC bug to me.

Have fun,
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!