Here you can find the source of printStackTrace()
Parameter | Description |
---|---|
s | <code>PrintStream</code> to use for output |
public static void printStackTrace()
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from ww w . j a v a2 s . c o m*/ * Prints this throwable and its backtrace to the specified print stream. * * @param s <code>PrintStream</code> to use for output */ public static void printStackTrace() { printStackTrace(System.err); } /** * Prints this throwable and its backtrace to the specified print stream. * * @param s <code>PrintStream</code> to use for output */ public static void printStackTrace(PrintStream s) { StackTraceElement[] trace = getStackTrace(2); synchronized (s) { for (int i = 0; i < trace.length; i++) s.println("\tat " + trace[i]); } } /** * Prints this throwable and its backtrace to the specified print stream. * * @param s <code>PrintStream</code> to use for output */ public static void printStackTrace(StackTraceElement[] trace, PrintStream s) { synchronized (s) { for (int i = 0; i < trace.length; i++) s.println("\tat " + trace[i]); } } /** * Prints this throwable and its backtrace to the specified print stream. * * @param s <code>PrintStream</code> to use for output */ public static void printStackTrace(StackTraceElement[] trace) { printStackTrace(trace, System.err); } /** * return the current stack trace * * @return non-null array of StackTraceElement */ public static StackTraceElement[] getStackTrace() { StackTraceElement[] ret = getStackTrace(1); return ret; } /** * return the current stack trace * * @return non-null array of StackTraceElement */ public static StackTraceElement[] getStackTrace(int drop) { Exception temp = new Exception(); StackTraceElement[] all = temp.getStackTrace(); int ndropped = 1 + drop; StackTraceElement[] ret = new StackTraceElement[all.length - ndropped]; for (int i = 0; i < ret.length; i++) { ret[i] = all[i + ndropped]; } // printStackTrace(ret); return ret; } }