Java Throwable to String getStackTraceOnly(Throwable throwable)

Here you can find the source of getStackTraceOnly(Throwable throwable)

Description

get Stack Trace Only

License

Open Source License

Declaration

public static String getStackTraceOnly(Throwable throwable) 

Method Source Code


//package com.java2s;
import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {

    public static String getStackTraceOnly(Throwable throwable) {
        String stackTrace = getStackTrace(throwable);

        if (stackTrace.indexOf("\tat") != -1) {
            return stackTrace.substring(stackTrace.indexOf("\tat"));
        } else {// w  w w . j av  a  2s  .  c  o  m
            return "";
        }
    }

    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        throwable.printStackTrace(pw);

        return sw.toString();
    }
}

Related

  1. getStackTraceAsText(Throwable t)
  2. getStackTraceFromBaseException(Throwable exc)
  3. getStackTraceFromThrowable(Throwable t)
  4. getStackTraceInString(Throwable throwable)
  5. getStackTraceLines(Throwable t, int numLines)
  6. getStackTraceString(final Throwable currentEx)
  7. getStackTraceString(Throwable cause, String delimiter, int maxLines)
  8. getStackTraceString(Throwable e)
  9. getStackTraceString(Throwable t)