Dean Blakely
Dean Blakely

Reputation: 3585

handle unhandled exceptions in Android

In Windows phone 7, developers are provided an Application_UnhandledException event that provides an exception object containing information and stack trace of any unhandled exception that occurs. There is an opportunity to store this object in local storage. On next startup we can check for such an object and email it to the developer. Obviously this is valuable in diagnosing production crashes.

Does such a thing exist in Android? Thanks, Gary

Upvotes: 3

Views: 2819

Answers (2)

zaman
zaman

Reputation: 786

Extend Application class

import android.app.Application;
import android.util.Log;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                Log.e("MyApplication", ex.getMessage());            

            }
        });
    }
}

Add the following line in AndroidManifest.xml file as Application attribute

android:name=".MyApplication"

Upvotes: 0

CombinatorX
CombinatorX

Reputation: 161

java.lang.Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler handler)

Is this what you want?

Upvotes: 8

Related Questions