use of java.lang.Thread.UncaughtExceptionHandler in project android_frameworks_base by ParanoidAndroid.
the class LayoutTestsExecutor method onCreate.
/** IMPLEMENTATION */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* It detects the crash by catching all the uncaught exceptions. However, we
* still have to kill the process, because after catching the exception the
* activity remains in a strange state, where intents don't revive it.
* However, we send the message to the service to speed up the rebooting
* (we don't have to wait for time-out to kick in).
*/
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable e) {
Log.w(LOG_TAG, "onTestCrashed(): " + mCurrentTestRelativePath + " thread=" + thread, e);
try {
Message serviceMsg = Message.obtain(null, ManagerService.MSG_CURRENT_TEST_CRASHED);
mManagerServiceMessenger.send(serviceMsg);
} catch (RemoteException e2) {
Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e2);
}
Process.killProcess(Process.myPid());
}
});
requestWindowFeature(Window.FEATURE_PROGRESS);
Intent intent = getIntent();
mTestsList = FsUtils.loadTestListFromStorage(intent.getStringExtra(EXTRA_TESTS_FILE));
mCurrentTestIndex = intent.getIntExtra(EXTRA_TEST_INDEX, -1);
mTotalTestCount = mCurrentTestIndex + mTestsList.size();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mScreenDimLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "WakeLock in LayoutTester");
mScreenDimLock.acquire();
bindService(new Intent(this, ManagerService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
}
use of java.lang.Thread.UncaughtExceptionHandler in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method throwingActionRoutedToHookAndThreadHandler.
@Test
public void throwingActionRoutedToHookAndThreadHandler() {
// TODO Test hook as well. Requires https://github.com/ReactiveX/RxJava/pull/3820.
Thread thread = Thread.currentThread();
UncaughtExceptionHandler originalHandler = thread.getUncaughtExceptionHandler();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
throwableRef.set(ex);
}
});
Worker worker = scheduler.createWorker();
final NullPointerException npe = new NullPointerException();
Runnable action = new Runnable() {
@Override
public void run() {
throw npe;
}
};
worker.schedule(action);
runUiThreadTasks();
Throwable throwable = throwableRef.get();
assertTrue(throwable instanceof IllegalStateException);
assertEquals("Fatal Exception thrown on Scheduler.", throwable.getMessage());
assertSame(npe, throwable.getCause());
// Restore the original uncaught exception handler.
thread.setUncaughtExceptionHandler(originalHandler);
}
use of java.lang.Thread.UncaughtExceptionHandler in project RxJava by ReactiveX.
the class RxJavaPlugins method uncaught.
static void uncaught(@NonNull Throwable error) {
Thread currentThread = Thread.currentThread();
UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
handler.uncaughtException(currentThread, error);
}
use of java.lang.Thread.UncaughtExceptionHandler in project RxJava by ReactiveX.
the class ScheduledRunnableTest method pluginCrash.
@Test
public void pluginCrash() {
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new TestException("Second");
}
});
CompositeDisposable set = new CompositeDisposable();
final ScheduledRunnable run = new ScheduledRunnable(new Runnable() {
@Override
public void run() {
throw new TestException("First");
}
}, set);
set.add(run);
try {
run.run();
fail("Should have thrown!");
} catch (TestException ex) {
assertEquals("Second", ex.getMessage());
} finally {
Thread.currentThread().setUncaughtExceptionHandler(null);
}
assertTrue(run.isDisposed());
assertEquals(0, set.size());
}
use of java.lang.Thread.UncaughtExceptionHandler in project RxJava by ReactiveX.
the class RxJavaPluginsTest method onErrorNoHandler.
@Test
public void onErrorNoHandler() {
try {
final List<Throwable> list = new ArrayList<Throwable>();
RxJavaPlugins.setErrorHandler(null);
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
list.add(e);
}
});
RxJavaPlugins.onError(new TestException("Forced failure"));
Thread.currentThread().setUncaughtExceptionHandler(null);
// this will be printed on the console and should not crash
RxJavaPlugins.onError(new TestException("Forced failure 3"));
assertEquals(1, list.size());
assertUndeliverableTestException(list, 0, "Forced failure");
} finally {
RxJavaPlugins.reset();
Thread.currentThread().setUncaughtExceptionHandler(null);
}
}
Aggregations