Java Stacktrace to String stackTraceStr(Exception e)

Here you can find the source of stackTraceStr(Exception e)

Description

stack Trace Str

License

Open Source License

Declaration

public static String stackTraceStr(Exception e) 

Method Source Code


//package com.java2s;
/*/*w  w w  . ja v a  2  s  .  com*/
 * Util.java - A utility codes.
 * 
 * Copyright (c) 2016 National Institute of Information and Communications
 * Technology, Japan
 *
 * You can redistribute it and/or modify it under either the terms of
 * the AGPLv3 or PIAX binary code license. See the file COPYING
 * included in the PIQT package for more in detail.
 */

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

public class Main {
    static public String newline = System.lineSeparator();

    public static String stackTraceStr(Exception e) {
        String ret = "";
        String msg = e.getMessage();
        if (msg != null) {
            ret += msg + newline;
        }
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        pw.flush();
        ret += sw.toString();
        return ret;
    }
}

Related

  1. stackTrace()
  2. stacktrace()
  3. stacktrace2string(StackTraceElement[] stackTraceElements)
  4. stackTraceAsString(Exception ex)
  5. stackTraceContains(String... needles)
  6. stackTraceString(Throwable t)
  7. stackTraceToString(Exception e)
  8. stackTraceToString(Exception e, int nBack)
  9. stackTraceToString(Exception ex, String message)