print Stack Trace - Android App

Android examples for App:Log

Description

print Stack Trace

Demo Code


//package com.java2s;

import android.util.Log;

public class Main {
    public static void printStackTrace(String TAG, Throwable ex) {
        StackTraceElement[] sta = ex.getStackTrace();
        if (ex.getMessage() != null) {
            Log.e(TAG, ex.getMessage());
        }//  w  w  w .  j  a v a2s.  com
        Log.e(TAG, ex.getClass().getName());
        for (StackTraceElement st : sta) {
            Log.e(TAG, "   " + st.getFileName() + "." + st.getMethodName()
                    + ": " + st.getLineNumber());
        }
    }
}

Related Tutorials