Java Throwable to String stackTraceToHTMLString(Throwable t)

Here you can find the source of stackTraceToHTMLString(Throwable t)

Description

stack Trace To HTML String

License

LGPL

Declaration

public static String stackTraceToHTMLString(Throwable t) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String stackTraceToHTMLString(Throwable t) {
        return stackTraceToHTMLString(t, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", "<br>");
    }/*from  w w w . j  av a2  s. com*/

    public static String stackTraceToHTMLString(Throwable t, String tab, String newLine) {
        String text = stackTraceToString(t);
        if (text == null) {
            return null;
        } else {
            return text.replace("\n", newLine).replace("\t", tab);
        }
    }

    public static String stackTraceToString(Throwable t) {
        if (t != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            t.printStackTrace(pw);
            return sw.toString();
        } else {
            return null;
        }
    }
}

Related

  1. stackTraceFromException(Throwable ex)
  2. stackTraceFromThrowable(Throwable throwable)
  3. stackTraceOf(Throwable e)
  4. stackTraceString(final Throwable exception)
  5. stackTraceToCharSequence( final Throwable error)
  6. stackTraceToString(final Throwable t)
  7. stackTraceToString(final Throwable thr)
  8. stackTraceToString(final Throwable throwable, final boolean expectNull)
  9. stackTraceToString(Throwable cause)