tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kees Jan Koster <kjkos...@kjkoster.org>
Subject Re: Custom error page with stacktrace
Date Sun, 24 Aug 2008 20:21:40 GMT
Dear All,

> In your error page, the variable "exception" is set to the exception
> (if any). You can get the error message and stack trace from the
> exception like this:
>
> <p>Exception message: <%= (exception == null) ? "" :
> exception.getMessage() %></p>
> <%
> String stStack = "";
> if (exception != null) {
> 	java.io.StringWriter sw = new java.io.StringWriter();
> 	exception.printStackTrace(new java.io.PrintWriter(sw));
> 	stStack = sw.toString();
> }
> %>
> <p>Stack trace:</p>
> <pre>
> <%= stStack %>
> </pre>
>

You can make this even more readable by using the individual stack  
trace elements instead of the string writer. That way you can give  
those lines that have your own classes a different colour. What I do  
is show my own classes in bold red in the stack trace. That way I know  
what code to check faster.

Check out http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html#getStackTrace()
--
Kees Jan

http://java-monitor.com/forum/
kjkoster@kjkoster.org
06-51838192

Rule 1 for being in a hole: stop digging.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message