Java Throwable to String getStackTraceString(Throwable t)

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

Description

get Stack Trace String

License

Open Source License

Declaration

public static List getStackTraceString(Throwable t) 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;

import java.util.List;

import java.util.StringTokenizer;

public class Main {
    public static List getStackTraceString(Throwable t) {
        List lines = new ArrayList();
        try {//from  ww  w .java2  s  .com
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            t.printStackTrace(ps);
            String stackTraces = baos.toString();
            StringTokenizer st = new StringTokenizer(stackTraces, "\n");
            while (st.hasMoreTokens()) {
                lines.add(st.nextToken());
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
            lines.add("X:" + e);
        }
        return lines;
    }
}

Related

  1. getStackTraceLines(Throwable t, int numLines)
  2. getStackTraceOnly(Throwable throwable)
  3. getStackTraceString(final Throwable currentEx)
  4. getStackTraceString(Throwable cause, String delimiter, int maxLines)
  5. getStackTraceString(Throwable e)
  6. getStackTraceString(Throwable throwable)
  7. getStackTraceString(Throwable throwable)
  8. getStackTraceString(Throwable tr)
  9. getStackTraceWithoutCause(Throwable throwable)