学习笔记之—PrintStackTrace方法

public class PrintStackTrace {
    public static void myPrintStackTrace(Throwable th){
        System.out.println(th);
        //System.err.println(th.getClass().getName()+": "+th.getMessage());
        StackTraceElement[] st = th.getStackTrace();
        for(StackTraceElement s:st)
            System.out.println("	at "+s.getClassName()+"."+s.getMethodName()+"("+s.getFileName()+":"
                    +s.getLineNumber()+")");
    }
}

这个方法打印后顺序会有变化这与IO流有关,还得多研究下源码

原文地址:https://www.cnblogs.com/hnzyyTl/p/4908692.html