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; } }
((UncaughtExceptionHandler) Thread.getDefaultUncaughtExceptionHandler()).setParentComponent(panel.get()); Dimension frameSize = new Dimension(Integer.parseInt(Configuration.INSTANCE.get("application.min.width")), Integer.parseInt(Configuration.INSTANCE.get("application.min.height")));
/** * Called when an uncaught exception is thrown. Will display the error message in a dialog box. * * @param t the thread where the exception was throws. * @param e the thrown exception. */ @Override public void uncaughtException(final Thread t, final Throwable e) { try { if (SwingUtilities.isEventDispatchThread()) { showException(t, e); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { showException(t, e); } }); } } catch (Exception excpt) { LOGGER.error("", excpt); } }
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); } }); }
Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable exception) { defaultHandler.uncaughtException( thread, exception );
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
@Override public void onCreate() { super.onCreate(); Crashlytics.start(this); initUncaughtExceptionHandler(); } private void initUncaughtExceptionHandler() { final ScheduledThreadPoolExecutor c = new ScheduledThreadPoolExecutor(1); c.schedule(new Runnable() { @Override public void run() { final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread paramThread, Throwable paramThrowable) { // do my amazing stuff here System.err.println("Error!"); //then pass the job to the previous handler defaultHandler.uncaughtException(paramThread, paramThrowable); } }); } }, 5, TimeUnit.SECONDS); }
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { ...
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void onUncaughtException(Throwable e) { // TODO Global Exception Handling ... } });
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 t, Throwable e) { // TODO implement this } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable t) { //Do something } });
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(); } }); } }
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { ... } });
@Override public void onCreate () { Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler(){ @Override public void uncaughtException(Thread arg0, Throwable arg1) { //mytoast here } } ); super.onCreate(); }