Java Stacktrace stackTrace(final Throwable caught)

Here you can find the source of stackTrace(final Throwable caught)

Description

stack Trace

License

Open Source License

Declaration

public static String stackTrace(final Throwable caught) 

Method Source Code

//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();
    }
}

Related

  1. stackTrace()
  2. stackTrace()
  3. stackTrace()
  4. stacktrace()
  5. stackTrace(final Exception t)
  6. stackTrace(int depth)
  7. stackTrace(StackTraceElement[] stackTrace)
  8. stackTrace2String(Throwable e)
  9. stackTraceApproved(StackTraceElement elt, String[] approved)