Java Formatter Usage displayStackTrace()

Here you can find the source of displayStackTrace()

Description

display Stack Trace

License

Open Source License

Declaration

public static String displayStackTrace() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Formatter;

public class Main {
    public static String displayStackTrace() {
        return displayStackTrace(null);
    }/*ww w .  jav a  2 s.c  om*/

    public static String displayStackTrace(StackTraceElement[] stack) {
        StringBuilder sb = new StringBuilder(256);
        Formatter f = new Formatter(sb);

        if (stack == null)
            stack = Thread.currentThread().getStackTrace();

        sb.append("stack trace:\n");

        for (StackTraceElement ste : stack) {
            String[] classInfo = ste.getClassName().split("\\.", -1);

            sb.append("\t");
            sb.append(classInfo[classInfo.length - 1]);
            sb.append(".");
            sb.append(ste.getMethodName());
            sb.append(" (");
            sb.append(ste.getClassName());
            sb.append(".java");
            //            sb.append(ste.getFileName());
            sb.append(":");
            sb.append(ste.getLineNumber());
            sb.append(")\n");
        }

        String rv = sb.toString();
        f.close();

        return sb.toString();
    }
}

Related

  1. convertRGBDecToHex(String decimal)
  2. convertTimeToString(double d, String timeFormat)
  3. convertToMillions(double tmp)
  4. createHexadecimalString(byte[] data)
  5. digestToString(byte[] input)
  6. echo(Formatter script, String label, String message, String file)
  7. encodeHex(byte[] bytes)
  8. escapeUnicode(String input)
  9. floatForSql(Float f)