ThreadPoolExecutor exec = new ThreadPoolExecutor...; exec.setThreadFactory(new ExceptionCatchingThreadFactory(exec.getThreadFactory())); //go on to submit tasks... private static class ExceptionCatchingThreadFactory implements ThreadFactory { private final ThreadFactory delegate; private ExceptionCatchingThreadFactory(ThreadFactory delegate) { this.delegate = delegate; } public Thread newThread(final Runnable r) { Thread t = delegate.newThread(r); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); //replace with your handling logic. } }); return t; } }
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void onUncaughtException(Throwable e) { // TODO Global Exception Handling ... } });
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { ...
public class ForceClose extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this)); setContentView(R.layout.main); // Your mechanism is ready now.. In this activity from anywhere if you get force close error it will be redirected to the CrashActivity. }}
UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler(){ @Override public void uncaughtException(Thread thread, Throwable ex) { //Here print the log... } }; Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // your code } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable ex) { // log, or create some statistics ... whatever } });
setContentView(R.layout.current); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); } code....
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // TODO Auto-generated method stub } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable t) { //Do something } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { // TODO implement this } });
public class MyApplication extends android.app.Application{ @Override public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread arg0, Throwable arg1) { doSomething(); } }); } }
public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces(); // print it ... } }); // ... continuing }
UncaughtExceptionHandler handler = new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable ex) { System.out.println(t.getName() + " " + ex); } }; thread.setUncaughtExceptionHandler(handler);
public void onCreate(){ Log.v("MyApplication", "onCreate triggered") Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){ public void uncaughtException(Thread thread, Throwable ex){ Log.v("MyApplication", "onUncaughtException triggered. Error:") ex.printStackTrace() //restart your app here like this Intent i = new Intent(this, TheClassYouWannaStart.class); getApplicationContext().startActivity(i); } }); }
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { System.out.println("I caught it !" + e); } }); throw new Exception(); }
//Inside your ApplicationClass public void onCreate(){ Log.v("MyApplication", "onCreate triggered") Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){ public void uncaughtException(Thread thread, Throwable ex){ Log.v("MyApplication", "onUncaughtException triggered. Error:") ex.printStackTrace() //restart your app here like this Intent i = new Intent(this, TheClassYouWannaStart.class); getApplicationContext().startActivity(i); } }); }
if (BuildConfig.DEBUG) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread paramThread, Throwable paramThrowable) { Log.wtf("Alert", paramThrowable.getMessage(), paramThrowable); System.exit(2); //Prevents the service/app from freezing } }); }
public MyBroadcastReceiver() { final UncaughtExceptionHandler defaultUEH = Thread .getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // TODO Handle Exception defaultUEH.uncaughtException(thread, ex); } }); }