@Override public void uncaughtException(Thread thread, Throwable ex) { Log.e(TAG, "TinkerUncaughtHandler catch exception:" + Log.getStackTraceString(ex)); ueh.uncaughtException(thread, ex);
exception); if (delegate != null) { delegate.uncaughtException(thread, exception);
defaultUEH.uncaughtException(t, e);
refiller.run(); } catch (Throwable e) { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
private void handleFatalFailure(Throwable error) { if( failure == null ) { failure = error; mqtt.tracer.debug("Fatal connection failure: %s", error); // Fail incomplete requests. ArrayList<Request> values = new ArrayList(requests.values()); requests.clear(); for (Request value : values) { if( value.cb!= null ) { value.cb.onFailure(failure); } } ArrayList<Request> overflowEntries = new ArrayList<Request>(overflow); overflow.clear(); for (Request entry : overflowEntries) { if( entry.cb !=null ) { entry.cb.onFailure(failure); } } if( listener !=null && !disconnected ) { try { listener.onFailure(failure); } catch (Exception e) { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); } } } }
/** * 这个是最关键的函数,当程序中有未被捕获的异常,系统将会自动调用#uncaughtException方法 * thread为出现未捕获异常的线程,ex为未捕获的异常,有了这个ex,我们就可以得到异常信息。 */ @Override public void uncaughtException(Thread thread, Throwable ex) { ex.printStackTrace(); if (!_handleException(ex) && mDefaultCrashHandler != null) { // 如果用户没有处理则让系统默认的异常处理器来处理 mDefaultCrashHandler.uncaughtException(thread, ex); } else { try { Thread.sleep(3000); } catch (InterruptedException e) { Log.e(TAG, "error : ", e); } // 退出程序,注释下面的重启启动程序代码 // android.os.Process.killProcess(android.os.Process.myPid()); // System.exit(1); // 重新启动程序,注释上面的退出程序 Intent intent = new Intent(); intent.setClass(mContext, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override public void uncaughtException(@Nullable Thread thread, @Nullable Throwable ex) { if (ex == null) return; try { ex.printStackTrace(); new AndroidBugReporter(activity).dumpBugReportToFile(); } catch (Exception e) { e.printStackTrace(); } // if (ex.getCause() instanceof InconsistentDatabaseException) // { // HabitsApplication app = (HabitsApplication) activity.getApplication(); // HabitList habits = app.getComponent().getHabitList(); // habits.repair(); // System.exit(0); // } if (originalHandler != null) originalHandler.uncaughtException(thread, ex); } }
if (!handleException(ex) && mDefaultHandler != null) { mDefaultHandler.uncaughtException(thread, ex); } else { try {
/** * 当UncaughtException发生时会转入该函数来处理 */ @Override public void uncaughtException(Thread thread, Throwable ex) { if (!handleException(ex) && mDefaultHandler != null) { //如果用户没有处理则让系统默认的异常处理器来处理 mDefaultHandler.uncaughtException(thread, ex); } else { DownloadBookService.cancel(); // 取消任务 LogUtils.i("取消下载任务"); new Thread(new Runnable() { @Override public void run() { Looper.prepare(); ToastUtils.showSingleToast("哎呀,程序发生异常啦..."); Looper.loop(); } }).start(); try { Thread.sleep(3000); } catch (InterruptedException e) { LogUtils.e("CrashHandler.InterruptedException--->" + e.toString()); } //退出程序 android.os.Process.killProcess(android.os.Process.myPid()); System.exit(1); } }
this.onKill.uncaughtException(this, e);
/** * Caught Exception */ @Override public void uncaughtException(Thread thread, Throwable ex) { if (!handleException(ex) && mDefaultHandler != null) { mDefaultHandler.uncaughtException(thread, ex); } else { try { Thread.sleep(100); } catch (InterruptedException e) { Logs.e("error : ", e); } Logs.d("uncaught exception is catched!"); System.exit(0); android.os.Process.killProcess(android.os.Process.myPid()); } }
/** * 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); } }
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 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) {} } } }
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(); } }
@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); } } }
public void onFailure(Throwable value) { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), value); } };
/** * 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); } } }
/** * 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); } }
/** * We want to send an analytics hit on any exception, then chain to other handlers (e.g., ACRA) */ synchronized private static void installDefaultExceptionHandler() { sOriginalUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { sendAnalyticsException(throwable, true); sOriginalUncaughtExceptionHandler.uncaughtException(thread, throwable); }); }