Here you can find the source of stackTrace(final Throwable caught)
public static String stackTrace(final Throwable caught)
//package com.java2s; /*//ww w. j a v a 2 s. co m * Copyright (C) 2008-2011 by Simon Hefti. All rights reserved. * Licensed under the EPL 1.0 (Eclipse Public License). * (see http://www.eclipse.org/legal/epl-v10.html) * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * * Initial Developer: Simon Hefti */ public class Main { public static String stackTrace(final Throwable caught) { StringBuffer sb = new StringBuffer(1024); sb.append("<pre>"); stackTrace(caught, sb); sb.append("</pre>"); return sb.toString(); } private static String stackTrace(final Throwable caught, final StringBuffer sb) { StackTraceElement[] st = caught.getStackTrace(); for (int i = 0; i < st.length; i++) { sb.append(st[i]); sb.append("<br/>"); } Throwable cause = caught.getCause(); if (null != cause) { sb.append("cause:<br/>"); stackTrace(caught, sb); } return sb.toString(); } }