0

when my app crashes it throws some lines in Logcat:

07-10 10:35:34.671  32391-32391/com.noframe.farmisagronom D/AndroidRuntime﹕ Shutting down VM
07-10 10:35:34.671  32391-32391/com.noframe.farmisagronom W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415bf8b0)

How to force app to print stack trace of exception?

my application class code:

public class Application extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        try {
            super.attachBaseContext(base);
            MultiDex.install(this);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public void onCreate() {

        try {
            Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    Log.e("Uncaught Exception detected in thread {}", t.getName(), e);
                }
            });
        } catch (SecurityException e) {
            Log.e("Could not set the Default Uncaught Exception Handler", "" ,e);
        }
        super.onCreate();
    }
}

Note that setDefaultUncaughtExceptionHandler is my try to get stack trace form exception, but it dose not work.

When i go wild with try-catch every where, i catch those exceptions. But that's not always an option, and requires a huge amount of time.

Alpha
  • 1,754
  • 3
  • 21
  • 39

2 Answers2

0

You can see the overrides of all the log methods Here's the link with (String tag, String msg, Throwable tr) signatures.

Passing an exception as the third parameter should give you the full stacktrace in logcat.

The three-argument log methods use the getStackTraceString() method

Shekhar
  • 812
  • 1
  • 8
  • 18
  • you can also look [here](http://developer.android.com/reference/android/util/Log.html#getStackTraceString%28java.lang.Throwable%29) and here's you can also see the solution [Need to handle uncaught exception and send log file](http://stackoverflow.com/questions/19897628/need-to-handle-uncaught-exception-and-send-log-file) – Shekhar Jul 10 '15 at 08:47
  • public static String getStackTraceString (Throwable tr) i assume? And i get that Throwable with voodoo magic or some special dance of uncaught exceptions? – Alpha Jul 13 '15 at 12:57
0

I did this way:

StackTraceElement[] st = new StackTraceElement[12];
st = ex.getStackTrace();
for (StackTraceElement el: st)
    com.example.android.common.logger.Log.e(TAG, " " + el);

Hope it will help.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Samuel Kogan
  • 121
  • 1
  • 3