public void create () { Thread.setDefaultUncaughtExceptionHandler(exHandler); }
private static void setGlobalUncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("UnCaughtException", e); } }); }
public static void setupDefaultUncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable thrown) { try { handleUncaughtException(thrown); } catch (Error err) { LOG.error("Received error in main thread.. terminating server...", err); Runtime.getRuntime().exit(-2); } } }); }
if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) { Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler( "/sdcard/<desired_local_path>", "http://<desired_url>/upload.php")); }
@Override public void testRunFinished(Result result) throws Exception { Thread.setDefaultUncaughtExceptionHandler(oldDefaultUncaughtExceptionHandler); System.err.println("Uninstalled aggressive uncaught exception handler"); synchronized (exceptions) { if (!exceptions.isEmpty()) { throw Throwables.rethrowAsException(exceptions.keySet().iterator().next()); } } } }
private ServerGroup(String name, int acceptorThreads, int workerThreads, EventLoopGroupMetrics eventLoopGroupMetrics) { this.name = name; this.acceptorThreads = acceptorThreads; this.workerThreads = workerThreads; this.eventLoopGroupMetrics = eventLoopGroupMetrics; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(final Thread t, final Throwable e) { LOG.error("Uncaught throwable", e); } }); Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(), "Zuul-ServerGroup-JVM-shutdown-hook")); }
@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()); } }); }
public class ForceClose extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); setContentView(R.layout.main); } }
public void initCatchException() { //设置该CrashHandler为程序的默认处理器 UnceHandler catchExcep = new UnceHandler(this); Thread.setDefaultUncaughtExceptionHandler(catchExcep); }
public class BaseActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread paramThread, Throwable paramThrowable) { Log.e("Alert","Lets See if it Works !!!"); } }); } }
public static void main(String[] args) throws Exception { LOG.info("Begin to start drpc server"); Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); final Drpc service = new Drpc(); service.init(); }
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); Thread.setDefaultUncaughtExceptionHandler(new TinkerUncaughtHandler(this)); onBaseContextAttached(base); }
private ServerGroup(String name, int acceptorThreads, int workerThreads, EventLoopGroupMetrics eventLoopGroupMetrics) { this.name = name; this.acceptorThreads = acceptorThreads; this.workerThreads = workerThreads; this.eventLoopGroupMetrics = eventLoopGroupMetrics; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(final Thread t, final Throwable e) { LOG.error("Uncaught throwable", e); } }); Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(), "Zuul-ServerGroup-JVM-shutdown-hook")); }
/** * start supervisor daemon */ public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); JStormServerUtils.startTaobaoJvmMonitor(); Supervisor instance = new Supervisor(); instance.run(); } }
try { CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(handler); IllegalStateException error = new IllegalStateException("Should be delivered to handler"); Flowable.error(error) Thread.setDefaultUncaughtExceptionHandler(originalHandler);
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); } }
CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); CapturingObserver<Object> observer = new CapturingObserver<Object>(); Thread.setDefaultUncaughtExceptionHandler(handler); IllegalStateException error = new IllegalStateException("Should be delivered to handler"); Flowable.error(error) Thread.setDefaultUncaughtExceptionHandler(originalHandler);
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); // read configuration files @SuppressWarnings("rawtypes") Map config = Utils.readStormConfig(); JStormServerUtils.startTaobaoJvmMonitor(); NimbusServer instance = new NimbusServer(); INimbus iNimbus = new DefaultInimbus(); instance.launchServer(config, iNimbus); }
@Override public void run() { new GCViewerGuiBuilder().initGCViewerGui(gcViewerGui, modelLoaderController); applyPreferences(gcViewerGui, new GCPreferences()); gcViewerGui.addWindowListener(GCViewerGuiController.this); Thread.setDefaultUncaughtExceptionHandler(new GCViewerUncaughtExceptionHandler(gcViewerGui)); gcViewerGui.setVisible(true); } };
@Test public void shouldQuitLooperAndThread() throws Exception { handlerThread = new HandlerThread("test"); Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); handlerThread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); handlerThread.start(); assertTrue(handlerThread.isAlive()); assertTrue(handlerThread.quit()); handlerThread.join(); assertFalse(handlerThread.isAlive()); handlerThread = null; }