Java Throwable to String getStackTrace(Throwable t)

Here you can find the source of getStackTrace(Throwable t)

Description

Returns a string representation of the stack trace of a Throwable

License

Open Source License

Parameter

Parameter Description
t the throwable

Return

a string containing the stack trace for the Throwable

Declaration

public static String getStackTrace(Throwable t) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Firestar 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://from   w ww  . j  a v a 2 s. com
 *     Firestar Software, Inc. - initial API and implementation
 *
 * Author:
 *     Gabriel Oancea
 *
 *******************************************************************************/

import java.io.*;

public class Main {
    /**
     * Returns a string representation of the stack trace of a Throwable
     * 
     * @param t the throwable
     * @return a string containing the stack trace for the Throwable
     */
    public static String getStackTrace(Throwable t) {
        StringWriter sw = new StringWriter(1024);
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(sw);
            t.printStackTrace(pw);
            pw.close();
        } catch (Exception ignored) {
        }
        return sw.toString();
    }
}

Related

  1. getStackTrace(Throwable t)
  2. getStackTrace(Throwable t)
  3. getStackTrace(Throwable t)
  4. getStackTrace(Throwable t)
  5. getStackTrace(Throwable t)
  6. getStackTrace(Throwable t)
  7. getStackTrace(Throwable t)
  8. getStackTrace(Throwable t)
  9. getStackTrace(Throwable t)