Java Throwable to String getExceptionString(Throwable e)

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

Description

get Exception String

License

Apache License

Declaration

public static String getExceptionString(Throwable e) 

Method Source Code

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

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

public class Main {
    public static String getExceptionString(Throwable e) {
        if (e == null)
            return "";

        StringWriter strWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(strWriter, true);
        e.printStackTrace(writer);//from  w  w  w.  ja va2  s.co  m
        StringBuffer sb = strWriter.getBuffer();
        String s = "cause by: \n\t" + sb.toString();

        return s.replace("Caused by:", "<font color='red'>Caused by:");
    }

    public static String toString(Object obj) {
        if (null == obj)
            return null;

        return String.valueOf(obj);
    }
}

Related

  1. getExceptionStack(final Throwable e)
  2. getExceptionStack(Throwable e)
  3. getExceptionStackTrace(Throwable ex)
  4. getExceptionStackTrace(Throwable exception)
  5. getExceptionStackTrace(Throwable exception)
  6. getExceptionString(Throwable t)
  7. getExceptionString(Throwable throwable)
  8. getExceptionText(Throwable e)
  9. getExceptionTrace(Throwable e)