Java Stacktrace to String getStackTrace()

Here you can find the source of getStackTrace()

Description

get Stack Trace

License

Open Source License

Declaration

public static String getStackTrace() 

Method Source Code


//package com.java2s;
/*//from ww w. ja v  a 2 s. c om
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String getStackTrace() {
        return getStackTrace(new Throwable());
    }

    public static String getStackTrace(Throwable t) {
        StringWriter writer = new StringWriter();
        t.printStackTrace(new PrintWriter(writer));
        return writer.toString();
    }
}

Related

  1. getStackTrace()
  2. getStackTrace(Exception e)
  3. getStackTrace(Exception e)
  4. getStackTrace(Exception e)
  5. getStackTrace(Exception e)