Here you can find the source of printStackTrace()
public static void printStackTrace()
//package com.java2s; /*/*from w ww . jav a 2 s .co m*/ * Copyright (c) 2007-2013, 2015 Eike Stepper (Berlin, Germany) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Eike Stepper - initial API and implementation * Christian W. Damus (CEA) - bug 376620: switch on primitive types */ import java.io.PrintStream; public class Main { public static void printStackTrace(PrintStream out, StackTraceElement[] stackTrace) { for (int i = 2; i < stackTrace.length; i++) { StackTraceElement stackTraceElement = stackTrace[i]; out.println("\tat " + stackTraceElement); //$NON-NLS-1$ } } public static void printStackTrace(StackTraceElement[] stackTrace) { printStackTrace(System.err, stackTrace); } /** * Prints the stack trace of the current thread to {@link System#err}. * * @since 3.4 */ public static void printStackTrace() { printStackTrace(Thread.currentThread().getStackTrace()); } }