Java Throwable to String printStackTrace(Throwable t)

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

Description

print Stack Trace

License

Open Source License

Declaration

public static void printStackTrace(Throwable t) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");

    public static void printStackTrace(Throwable t) {
        serr();//from   w  w  w. j a v  a2  s.  c  o m
        t.printStackTrace();
    }

    public static void serr(String ln) {
        println(System.err, ln);
    }

    public static void serr() {
        serr("");
    }

    public static void serr(Object obj) {
        serr(obj.toString());
    }

    private static void println(PrintStream ps, String ln) {
        ps.println(getStringBuilder().append(ln));
    }

    private static StringBuilder getStringBuilder() {
        StringBuilder sb = new StringBuilder("[");
        sb.append(dateFormat.format(new Date()));
        sb.append("] ");
        return sb;
    }
}

Related

  1. getStackTraceString(Throwable t)
  2. getStackTraceString(Throwable throwable)
  3. getStackTraceString(Throwable throwable)
  4. getStackTraceString(Throwable tr)
  5. getStackTraceWithoutCause(Throwable throwable)
  6. serialize(Throwable t)
  7. serializeStackTrace(Throwable _t)
  8. serializeStackTrace(Throwable th)
  9. stackToString(Exception e)