Yes, you can do that.

1. Make sure your web.xml has an error-page declaration for
exception-type java.lang.Throwable. (Throwable catches things like
OutOfMemoryError, as well as Exception and its subclasses.)

2. In your error handling page the exception is available as a request
attribute, either "javax.servlet.jsp.jspException" or
"javax.servlet.error.exception". (I think the first is for errors
thrown from a JSP page and the second for errors thrown from a
servlet.) I do this:
    Throwable ex =
(Throwable)request.getAttribute("javax.servlet.jsp.jspException");
    if (ex == null)
        ex = (Throwable)request.getAttribute("javax.servlet.error.exception");
    if (ex != null) { [etc.]

3. As Eduard said, you can get the stack trace by:
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    String st = sw.toString();

--
Len


On 3/15/06, Andrew Stepanenko <[EMAIL PROTECTED]> wrote:
> Hello Eduard,
>
> thank you for your answer. But I actually asked about run-time
> exceptions, like OutOfMemoryError. Do you think this approach will go
> for them too?
>
> Andrew.
>
> Eduard Wirch wrote:
> > Use this:
> >
> > } catch (Exception e) {
> >     java.io.StringWriter stackTrace = new java.io.StringWriter();
> >     e.printStackTrace(new java.io.PrintWriter(stackTrace));
> >     request.setAttribute("error", stackTrace.toString());
> > }
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Andrew Stepanenko [mailto:[EMAIL PROTECTED]
> > Gesendet: Dienstag, 14. März 2006 08:33
> > An: users@tomcat.apache.org
> > Betreff: Programmatic access to error 500 stack trace
> >
> > Hello,
> >
> > In our web app I as a developer want to know when the error 500 occurred
> > (either because of OutOfMemory or whatever). So, I defined a custom
> > error page in my web.xml and put there email sending logic. It is easy
> > for me to get the error code, but can I access the actual exception
> > stack trace so that I may embed it into my email message?
> >
> > Thank you,
> > Andrew Stepanenko.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to