Here you can find the source of stackTrace(Throwable e)
public static String stackTrace(Throwable e)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Pivotal Software, Inc. and others. * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). * * Contributors:/*from w w w. j a v a 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(Throwable e) { try { ByteArrayOutputStream trace = new ByteArrayOutputStream(); PrintStream dump = new PrintStream(trace, true, "utf8"); e.printStackTrace(dump); return trace.toString("utf8"); } catch (Exception shouldNotHappen) { throw new RuntimeException(shouldNotHappen); } } }