----- Original Message -----

> From: Donald Jolley <jolleyt...@gmail.com>
> To: Tomcat Users List <users@tomcat.apache.org>
> Cc: 
> Sent: Monday, August 29, 2011 5:38 PM
> Subject: Re: Exception Handling
> 
>>  Like... what other information do you want to
>>  provide? An explanation of what to do to avoid the error? That is
>>  worthy of a Turing Award if you can pull it off :)
> 
> I am interested in identifying as clearly as possible the specific code that
> was the root cause of the error.  The "original URI" that you 
> mentioned
> sounded helpful.  So far I have not been able to figure out how to do that.
> I was able to add a stack trace.
> 
> So far, I am quite willing to live with what I have.  Thanks for your input.
> 
>          ... doug
>

There's an implicit object called pageContext.


The javadoc for that (javax.servlet.jsp.PageContext) has a lot of interesting 
information.

One of the methods is getErrorData. Looking at the javadoc for ErrorData 
(javax.servlet.jsp.ErrorData), there's a method called getRequestURI. This 
sounds exactly like what you're looking for:

${pageContext.errorData.requestURI} will give you the URI.

Also in the javadoc for pageContext, there's a method called getException, 
which returns an Exception object.

java.lang.Exception implements java.lang.Throwable, which has a lot of nice 
information.

One nice one is getMessage, which may give a more detailed message than the 
default toString. You could access that by:

${pageContext.exception.message}

Another one is getStackTrace, which returns an array of StackTraceElement. So 
you could
print the stack trace using the following code (if you've included the standard 
tag lib):

<c:forEach var="st" items="${pageContext.exception.stackTrace}">
   ${st}<br>
</c:forEach>

This makes use of the StackTraceElement.toString() method. There are obviously 
more games you can play. For example, if you don't want the entire stack trace, 
you can do this:

${pageContext.exception.stackTrace[0].fileName}<br>
${pageContext.exception.stackTrace[0].lineNumber}<br>
${pageContext.exception.stackTrace[0].className}<br>

There may be more than one class you're responsible for, so the first entry in 
the array might not be the most interesting one. Here's a slightly different 
foreach loop which just dumps class names and line numbers:

<c:forEach var="st" items="{pageContext.exception.stackTrace}">
   ${st.className} ${st.lineNumber}<br>
</c:forEach>

See the java.lang.StackTraceElement for other useful features.

In short, look at implicit objects, then see what's populated when 
isErrorPage="true" is set, and finally look at the javadoc for the classes.


. . . . just my two cents.
/mde/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to