Here you can find the source of printErrorMsgTraceAsCause(Throwable throwable, StackTraceElement[] causedTrace)
Parameter | Description |
---|---|
throwable | the throwable |
causedTrace | the caused trace |
public static void printErrorMsgTraceAsCause(Throwable throwable, StackTraceElement[] causedTrace)
//package com.java2s; //License from project: Apache License public class Main { /**// w ww . j a v a2 s . c o m * Print error msg trace as cause. * * @param throwable the throwable * @param causedTrace the caused trace */ public static void printErrorMsgTraceAsCause(Throwable throwable, StackTraceElement[] causedTrace) { // assert Thread.holdsLock(s); // Compute number of frames in common between this and caused StackTraceElement[] trace = throwable.getStackTrace(); int m = trace.length - 1, n = causedTrace.length - 1; while (m >= 0 && n >= 0 && trace[m].equals(causedTrace[n])) { m--; n--; } int framesInCommon = trace.length - 1 - m; // ConsoleColorUtils.printRed(new // StringBuffer().append("\t\t\t\tCaused by: ") // .append(throwable).toString()); System.err.println(new StringBuffer().append("\t\t\t\tCaused by: ").append(throwable).toString()); // System.out.println(); for (int i = 0; i <= m; i++) { // ConsoleColorUtils.printRed(new // StringBuffer().append("\n\t\t\t\tat " + trace[i]) // .toString()); System.err.println(new StringBuffer().append("\n\t\t\t\tat " + trace[i]).toString()); // System.out.println(); } if (framesInCommon != 0) // ConsoleColorUtils.printRed(new // StringBuffer().append("\n\t\t\t\t... ") // .append(framesInCommon).append(" more\n").toString()); System.err.println(new StringBuffer().append("\n\t\t\t\t... ").append(framesInCommon).append(" more\n") .toString()); // System.out.println(); // Recurse if we have a cause Throwable ourCause = throwable.getCause(); if (ourCause != null) printErrorMsgTraceAsCause(ourCause, trace); } }