Codota Logo
Thread.setDefaultUncaughtExceptionHandler
Code IndexAdd Codota to your IDE (free)

How to use
setDefaultUncaughtExceptionHandler
method
in
java.lang.Thread

Best Java code snippets using java.lang.Thread.setDefaultUncaughtExceptionHandler (Showing top 20 results out of 3,492)

  • Common ways to obtain Thread
private void myMethod () {
Thread t =
  • Codota IconThread.currentThread()
  • Codota IconRunnable target;new Thread(target)
  • Codota IconRunnable target;String name;new Thread(target, name)
  • Smart code suggestions by Codota
}
origin: libgdx/libgdx

public void create () {
  Thread.setDefaultUncaughtExceptionHandler(exHandler);
}
origin: alibaba/canal

private static void setGlobalUncaughtExceptionHandler() {
  Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread t, Throwable e) {
      logger.error("UnCaughtException", e);
    }
  });
}
origin: apache/storm

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);
      }
    }
  });
}
origin: stackoverflow.com

 if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
  Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(
      "/sdcard/<desired_local_path>", "http://<desired_url>/upload.php"));
}
origin: square/okhttp

 @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());
   }
  }
 }
}
origin: Netflix/zuul

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"));
}
origin: square/okhttp

@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());
  }
 });
}
origin: stackoverflow.com

 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);
  }
}
origin: aa112901/remusic

public void initCatchException() {
  //设置该CrashHandler为程序的默认处理器
  UnceHandler catchExcep = new UnceHandler(this);
  Thread.setDefaultUncaughtExceptionHandler(catchExcep);
}
origin: stackoverflow.com

 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 !!!");
      }
    });
  }
}
origin: alibaba/jstorm

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();
}
origin: Tencent/tinker

@Override
protected void attachBaseContext(Context base) {
  super.attachBaseContext(base);
  Thread.setDefaultUncaughtExceptionHandler(new TinkerUncaughtHandler(this));
  onBaseContextAttached(base);
}
origin: Netflix/zuul

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"));
}
origin: alibaba/jstorm

  /**
   * start supervisor daemon
   */
  public static void main(String[] args) {
    Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
    JStormServerUtils.startTaobaoJvmMonitor();
    Supervisor instance = new Supervisor();
    instance.run();
  }
}
origin: ReactiveX/RxJava

try {
  CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();
  Thread.setDefaultUncaughtExceptionHandler(handler);
  IllegalStateException error = new IllegalStateException("Should be delivered to handler");
  Flowable.error(error)
  Thread.setDefaultUncaughtExceptionHandler(originalHandler);
origin: ReactiveX/RxJava

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);
  }
}
origin: ReactiveX/RxJava

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);
origin: alibaba/jstorm

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);
}
origin: chewiebug/GCViewer

  @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);
  }
};
origin: robolectric/robolectric

@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;
}
java.langThreadsetDefaultUncaughtExceptionHandler

Javadoc

Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.

Uncaught exception handling is controlled first by the thread, then by the thread's ThreadGroup object and finally by the default uncaught exception handler. If the thread does not have an explicit uncaught exception handler set, and the thread's thread group (including parent thread groups) does not specialize its uncaughtException method, then the default handler's uncaughtException method will be invoked.

By setting the default uncaught exception handler, an application can change the way in which uncaught exceptions are handled (such as logging to a specific device, or file) for those threads that would already accept whatever "default" behavior the system provided.

Note that the default uncaught exception handler should not usually defer to the thread's ThreadGroup object, as that could cause infinite recursion.

Popular methods of Thread

  • currentThread
  • sleep
    Causes the currently executing thread to sleep (temporarily cease execution) for the specified numbe
  • <init>
    Constructs a new Thread with no Runnable object, the given name and belonging to the ThreadGroup pas
  • start
    Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread
  • getContextClassLoader
    Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator
  • interrupt
    Interrupts this thread. Unless the current thread is interrupting itself, which is always permitted,
  • setDaemon
    Marks this thread as either a #isDaemon thread or a user thread. The Java Virtual Machine exits when
  • getName
    Returns this thread's name.
  • join
    Waits at most millis milliseconds plus nanos nanoseconds for this thread to die. This implementatio
  • setContextClassLoader
    Sets the context ClassLoader for this Thread. The context ClassLoader can be set when a thread is cr
  • setName
    Changes the name of this thread to be equal to the argumentname. First the checkAccess method of thi
  • interrupted
    Tests whether the current thread has been interrupted. Theinterrupted status of the thread is cleare
  • setName,
  • interrupted,
  • getStackTrace,
  • getId,
  • isInterrupted,
  • isAlive,
  • setPriority,
  • yield,
  • getThreadGroup,
  • getPriority

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • orElseThrow (Optional)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Timer (java.util)
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be s
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Table (org.hibernate.mapping)
    A relational table
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now