Java Stacktrace to String stacktrace()

Here you can find the source of stacktrace()

Description

stacktrace

License

Open Source License

Declaration

public static String stacktrace() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Pivotal 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:// w w  w . java 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() {
        return stacktrace(new Exception("Stacktrace"));
    }

    public static String stacktrace(Exception exception) {
        ByteArrayOutputStream dump = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(dump);
        try {
            exception.printStackTrace(out);
        } finally {
            out.close();
        }
        return dump.toString();
    }
}

Related

  1. getStackTraceStr(Exception e)
  2. getStackTraceString()
  3. getStackTraceString(Exception e)
  4. getStackTraceString(Exception e)
  5. stackTrace()
  6. stacktrace2string(StackTraceElement[] stackTraceElements)
  7. stackTraceAsString(Exception ex)
  8. stackTraceContains(String... needles)
  9. stackTraceStr(Exception e)