get Error Stack Trace Message - Android java.lang

Android examples for java.lang:Throwable

Description

get Error Stack Trace Message

Demo Code


//package com.java2s;

import java.io.PrintWriter;

public class Main {
    public static void getErrorStackTraceMessage(StackTraceElement stack[],
            PrintWriter pw, int count) {
        int ix = stack.length - 1;
        int c = count;
        while (ix > 0) {
            StackTraceElement frame = stack[ix];
            String cname = frame.getClassName();
            if (cname.equals("java.util.logging.Logger")) {
                break;
            }/*from   www  . j a va2s  .  c o m*/
            String mname = frame.getMethodName();
            int linenumber = frame.getLineNumber();
            pw.print(cname + ":" + mname + ":" + linenumber);
            pw.print("\n");
            c--;
            if (c < 1)
                break;
            ix--;
        }
    }
}

Related Tutorials