public UnceHandler(MainApplication application) { //获取系统默认的UncaughtException处理器 mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); this.application = application; }
if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) { Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler( "/sdcard/<desired_local_path>", "http://<desired_url>/upload.php")); }
/** * 初始化 * * @param context */ public void init(Context context) { mContext = context; //获取系统默认的UncaughtException处理器 mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); //设置该CrashHandler为程序的默认处理器 Thread.setDefaultUncaughtExceptionHandler(this); }
public BaseExceptionHandler(@NonNull BaseActivity activity) { this.activity = activity; originalHandler = Thread.getDefaultUncaughtExceptionHandler(); }
@Override public void onFailure(Throwable t) { LOG.error("Wait queue scheduler worker exited with failure!", t); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t); } }
public void init(Context context) { mDefaultCrashHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); mContext = context.getApplicationContext(); }
public TinkerUncaughtHandler(Context context) { this.context = context; ueh = Thread.getDefaultUncaughtExceptionHandler(); crashFile = SharePatchFileUtil.getPatchLastCrashFile(context); }
@Override public void testRunStarted(Description description) { System.err.println("Installing aggressive uncaught exception handler"); oldDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { StringWriter errorText = new StringWriter(256); errorText.append("Uncaught exception in OkHttp thread \""); errorText.append(thread.getName()); errorText.append("\"\n"); throwable.printStackTrace(new PrintWriter(errorText)); errorText.append("\n"); if (lastTestStarted != null) { errorText.append("Last test to start was: "); errorText.append(lastTestStarted.getDisplayName()); errorText.append("\n"); } System.err.print(errorText.toString()); synchronized (exceptions) { exceptions.put(throwable, lastTestStarted.getDisplayName()); } }); }
@Override public void onFailure(Throwable t) { if (t instanceof CancellationException && isShutdown.get()) { LOG.info("AMReporter QueueDrainer exited as a result of a cancellation after shutdown"); } else { LOG.error("AMReporter QueueDrainer exited with error", t); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t); } } });
public static void registerErrorHandler() { UncaughtExceptionHandler dueh = Thread.getDefaultUncaughtExceptionHandler(); if (dueh == null) { LOGGER.log(Level.FINE, "Installing default uncaught exception handler"); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { LOGGER.log(Level.SEVERE, "Uncaught exception in thread " + t.getName() + " with ID " + t.getId() + ": " + e.getMessage(), e); } }); } } }
private void insertIntoPreemptionQueueOrFailUnlocked(TaskWrapper taskWrapper) { boolean added = preemptionQueue.offer(taskWrapper); if (!added) { LOG.warn("Failed to add element {} to preemption queue. Terminating", taskWrapper); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), new IllegalStateException("Preemption queue full. Cannot proceed")); } }
@Override public void onSuccess(Object result) { if (isShutdown.get()) { LOG.info("Wait queue scheduler worker exited with success!"); } else { LOG.error("Wait queue scheduler worker exited with success!"); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), new IllegalStateException("WaitQueue worked exited before shutdown")); } }
/** * 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); }
/** * 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); } } }
/** * 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); }); }
@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; } }
@Before public void setup() throws Exception { zk = new ZooKeeperTestingServerManager(); dueh = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable th) {} }); stateDir = Files.createTempDirectory("helios-agent-conflict-test"); first = makeAgent("first"); second = makeAgent("second"); }
Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler(); try { CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();
private static void expectUncaughtTestException(Action action) { Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler(); CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(handler); RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() { @Override public void accept(Throwable error) throws Exception { Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), error); } }); try { action.run(); assertEquals("Should have received exactly 1 exception", 1, handler.count); Throwable caught = handler.caught; while (caught != null) { if (caught instanceof TestException) { break; } if (caught == caught.getCause()) { break; } caught = caught.getCause(); } assertTrue("A TestException should have been delivered to the handler", caught instanceof TestException); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } finally { Thread.setDefaultUncaughtExceptionHandler(originalHandler); RxJavaPlugins.setErrorHandler(null); } }
Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler(); try { CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();