Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Global Exception Handling on android
Stackoverflow Link:
Handle uncaughtException, start activity:
public class MyApplication extends Application
public void onCreate ()
// Setup handler for uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
public void uncaughtException (Thread thread, Throwable e)
handleUncaughtException (thread, e);
public void handleUncaughtException (Thread thread, Throwable e)
e.printStackTrace(); // not all Android versions will print the stack trace automatically
Intent intent = new Intent ();
intent.setAction ("com.mydomain.SEND_LOG"); // see step 5.
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
startActivity (intent);
System.exit(1); // kill off the crashed app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment