Java Stacktrace Print printStackTraceHTML(Throwable e)

Here you can find the source of printStackTraceHTML(Throwable e)

Description

print Stack Trace HTML

License

Open Source License

Declaration

public static String printStackTraceHTML(Throwable e) 

Method Source Code

//package com.java2s;
/*/*from w ww  .  j  a v  a2 s.  c  o  m*/
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-04 Wolfgang M. Meier
 *  wolfgang@exist-db.org
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 *  $Id$
 */

public class Main {
    public static String printStackTraceHTML(Throwable e) {
        final StringBuilder buf = new StringBuilder();
        final StackTraceElement[] trace = e.getStackTrace();
        buf.append("<table id=\"javatrace\">");
        buf.append("<caption>Java Stack Trace:</caption>");
        buf.append("<tr><th>Class Name</th><th>Method Name</th><th>File Name</th><th>Line</th></tr>");
        for (int i = 0; i < trace.length && i < 20; i++) {
            buf.append("<tr>");
            buf.append("<td class=\"class\">").append(trace[i].getClassName()).append("</td>");
            buf.append("<td class=\"method\">").append(trace[i].getMethodName()).append("</td>");
            buf.append("<td class=\"file\">")
                    .append(trace[i].getFileName() == null ? "Unknown" : trace[i].getFileName()).append("</td>");
            buf.append("<td class=\"line\">");
            buf.append(trace[i].getLineNumber() < 0 ? "Unavailable" : Integer.toString(trace[i].getLineNumber()));
            buf.append("</td>");
            buf.append("</tr>");
        }
        buf.append("</table>");
        return buf.toString();
    }
}

Related

  1. printStackTrace(Throwable t)
  2. printStackTrace(Throwable throwable)
  3. printStackTrace(Throwable throwable)
  4. printStackTraceAsHtml(Throwable t)
  5. printStackTraceElement(StackTraceElement element, StringBuilder buffer)
  6. printStackTraces()
  7. printStackTraceToOutputStream(Throwable t, OutputStream out)
  8. printStackTraceToString(final Throwable t)
  9. printStackTraceToString(Throwable aThrowable)