- Common ways to obtain Thread$UncaughtExceptionHandler
private void myMethod () {Thread$UncaughtExceptionHandler t =
Thread.getDefaultUncaughtExceptionHandler()
new Exiter(Runtime.getRuntime())
String className;(UncaughtExceptionHandler) ClassLoader.getSystemClassLoader().loadClass(className).newInstance()
- Smart code suggestions by Codota
}
@Override public void accept(Throwable error) throws Exception { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), error); } });
/** * Send @param t to the default uncaught exception handler, or log it if none such is set up */ public static void handleOrLog(Throwable t) { if (Thread.getDefaultUncaughtExceptionHandler() == null) logger.error("Error in ThreadPoolExecutor", t); else Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t); }
@Override public void uncaughtException(Thread thread, Throwable ex) { TinkerLog.e(TAG, "uncaughtException:" + ex.getMessage()); tinkerFastCrashProtect(); tinkerPreVerifiedCrashHandler(ex); ueh.uncaughtException(thread, ex); }
/** * The executor re-throws exceptions thrown by the task to the uncaught exception handler * so we only need to do anything if uncaught exception handler has not been se */ private void logAndHandle(Throwable t, boolean passToHandler) { if (Thread.getDefaultUncaughtExceptionHandler() == null) { LOG.error("Unhandled exception on thread {}", Thread.currentThread().getName(), t); } else { LOG.info("Unhandled exception on thread {}", Thread.currentThread().getName(), t); if (passToHandler) { Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t); } } }
static void handleError(Throwable ex) { Thread thread = Thread.currentThread(); Throwable t = unwrap(ex); Thread.UncaughtExceptionHandler x = thread.getUncaughtExceptionHandler(); if (x != null) { x.uncaughtException(thread, t); } else { log.error("Scheduler worker failed with an uncaught exception", t); } if (onHandleErrorHook != null) { onHandleErrorHook.accept(thread, t); } }
private void givenUncaughtException(final KsqlException e) { ehCapture.getValue().uncaughtException(new Thread(), e); }
/** * pass-through to default handler * * @param t the crashed thread * @param e the uncaught exception */ public void handReportToDefaultExceptionHandler(@Nullable Thread t, @NonNull Throwable e) { if (defaultExceptionHandler != null) { ACRA.log.i(LOG_TAG, "ACRA is disabled for " + context.getPackageName() + " - forwarding uncaught Exception on to default ExceptionHandler"); defaultExceptionHandler.uncaughtException(t, e); } else { ACRA.log.e(LOG_TAG, "ACRA is disabled for " + context.getPackageName() + " - no default ExceptionHandler"); ACRA.log.e(LOG_TAG, "ACRA caught a " + e.getClass().getSimpleName() + " for " + context.getPackageName(), e); } }
/** * Close the file and the storage, without writing anything. * This method ignores all errors. */ private void closeImmediately() { try { closeStorage(); } catch (Exception e) { if (backgroundExceptionHandler != null) { backgroundExceptionHandler.uncaughtException(null, e); } } }
public void onFailure(Throwable value) { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), value); } };
@Override public void uncaughtException(Thread thread, Throwable ex) { try { if (isPassedToParent(ex) && this.parent != null) { this.parent.uncaughtException(thread, ex); } } finally { this.loggedExceptions.clear(); if (this.exitCode != 0) { System.exit(this.exitCode); } } }
void safeRun(final Runnable task) { assert ! holdsLock(headLock) && ! holdsLock(tailLock); try { if (task != null) task.run(); } catch (Throwable t) { try { exceptionHandler.uncaughtException(Thread.currentThread(), t); } catch (Throwable ignored) { // nothing else we can safely do here } } finally { // clear TCCL JBossExecutors.clearContextClassLoader(Thread.currentThread()); // clear interrupt status Thread.interrupted(); } }
private IllegalStateException panic(IllegalStateException e) { if (backgroundExceptionHandler != null) { backgroundExceptionHandler.uncaughtException(null, e); } panicException = e; closeImmediately(); return e; }
@Override public void uncaughtException(Thread thread, Throwable ex) { Log.e(TAG, "TinkerUncaughtHandler catch exception:" + Log.getStackTraceString(ex)); ueh.uncaughtException(thread, ex);
@Test(expectedExceptions = RuntimeException.class) public void testUncaughtException() { Logger logger = Mockito.mock(Logger.class); Thread thread = new Thread(); thread.setName("foo"); RuntimeException runtimeException = new RuntimeException(); String errorMessage = String.format("Thread %s threw an uncaught exception: %s", thread, runtimeException); Mockito.doThrow(runtimeException).when(logger).error(errorMessage, runtimeException); Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new LoggingUncaughtExceptionHandler(Optional.of(logger)); uncaughtExceptionHandler.uncaughtException(thread, runtimeException); } }
public void run() { Runnable task; for (;;) { synchronized (this) { task = poll(); if (task == null) { runCount--; return; } } try { task.run(); } catch (Throwable t) { final Thread.UncaughtExceptionHandler handler = LimitedExecutor.this.handler; if (handler != null) try { handler.uncaughtException(Thread.currentThread(), t); } catch (Throwable ignored) {} } } }
/** * End the application. */ private void endApplication(@Nullable Thread uncaughtExceptionThread, Throwable th) { final boolean letDefaultHandlerEndApplication = config.alsoReportToAndroidFramework(); final boolean handlingUncaughtException = uncaughtExceptionThread != null; if (handlingUncaughtException && letDefaultHandlerEndApplication && defaultExceptionHandler != null) { // Let the system default handler do it's job and display the force close dialog. if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Handing Exception on to default ExceptionHandler"); defaultExceptionHandler.uncaughtException(uncaughtExceptionThread, th); } else { processFinisher.endApplication(); } }
private static void finalizerTimedOut(Object object) { // The current object has exceeded the finalization deadline; abort! String message = object.getClass().getName() + ".finalize() timed out after " + (MAX_FINALIZE_NANOS / NANOS_PER_SECOND) + " seconds"; Exception syntheticException = new TimeoutException(message); // We use the stack from where finalize() was running to show where it was stuck. syntheticException.setStackTrace(FinalizerDaemon.INSTANCE.getStackTrace()); Thread.UncaughtExceptionHandler h = Thread.getDefaultUncaughtExceptionHandler(); if (h == null) { // If we have no handler, log and exit. System.logE(message, syntheticException); System.exit(2); } // Otherwise call the handler to do crash reporting. // We don't just throw because we're not the thread that // timed out; we're the thread that detected it. h.uncaughtException(Thread.currentThread(), syntheticException); } }
public static void report(Throwable e){ if(e == null) return; try{ //debug(e); warn("reporting", Log.getStackTraceString(e)); if(eh != null){ eh.uncaughtException(Thread.currentThread(), e); } }catch(Exception ex){ ex.printStackTrace(); } }
/** * Handles uncaught exceptions. Any uncaught exception in any {@code Thread} * is forwarded to the thread's {@code ThreadGroup} by invoking this * method. * * <p>New code should use {@link Thread#setUncaughtExceptionHandler} instead of thread groups. * * @param t the Thread that terminated with an uncaught exception * @param e the uncaught exception itself */ public void uncaughtException(Thread t, Throwable e) { if (parent != null) { parent.uncaughtException(t, e); } else if (Thread.getDefaultUncaughtExceptionHandler() != null) { // TODO The spec is unclear regarding this. What do we do? Thread.getDefaultUncaughtExceptionHandler().uncaughtException(t, e); } else if (!(e instanceof ThreadDeath)) { // No parent group, has to be 'system' Thread Group e.printStackTrace(System.err); } }
@Override public final void run() { try { if (!mGifDrawable.isRecycled()) { doWork(); } } catch (Throwable throwable) { final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); if (uncaughtExceptionHandler != null) { uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), throwable); } throw throwable; } }