Java Throwable to String getStackTrace(Throwable ex)

Here you can find the source of getStackTrace(Throwable ex)

Description

get Stack Trace

License

Open Source License

Declaration

public static String getStackTrace(Throwable ex) 

Method Source Code


//package com.java2s;
/*//from w  w  w .j  a  v a 2 s .  c om
 *   Copyright (c) 2006-2010 Marvisan Pty. Ltd. All rights reserved.6
 *               Use is subject to license terms.
 */

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

public class Main {
    public static String getStackTrace(Throwable ex) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        pw.write("\n---------------------- EXCEPTION STACK TRACE ----------------------\n");
        ex.printStackTrace(pw);
        if (ex.getCause() != null) {
            pw.write("\n---------------------- CAUSE EXCEPTION STACK TRACE ----------------------\n");
            ex.getCause().printStackTrace(pw);
            pw.write("\n---------------------- CAUSE EXCEPTION STACK TRACE ----------------------\n");
        }
        pw.write("\n---------------------- EXCEPTION STACK TRACE ----------------------\n");
        pw.flush();
        sw.flush();

        return sw.toString();
    }
}

Related

  1. getStackTrace(Throwable aThrowable)
  2. getStackTrace(Throwable e)
  3. getStackTrace(Throwable e)
  4. getStackTrace(Throwable e)
  5. getStackTrace(Throwable ex)
  6. getStackTrace(Throwable ex)
  7. getStackTrace(Throwable exc)
  8. getStackTrace(Throwable exception)
  9. getStackTrace(Throwable exception)