Here you can find the source of stacktrace()
public static String stacktrace()
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Pivotal Software, Inc. * 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:// w w w . java 2s . c o m * Pivotal Software, Inc. - initial API and implementation *******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.PrintStream; public class Main { public static String stacktrace() { return stacktrace(new Exception("Stacktrace")); } public static String stacktrace(Exception exception) { ByteArrayOutputStream dump = new ByteArrayOutputStream(); PrintStream out = new PrintStream(dump); try { exception.printStackTrace(out); } finally { out.close(); } return dump.toString(); } }