@Override
  public void uncaughtException(Thread t, Throwable e) {
    if(ShutdownHookManager.get().isShutdownInProgress()) {
      LOG.error("Thread " + t + " threw an Throwable, but we are shutting " +
      		"down, so ignoring this", e);
    } else if(e instanceof Error) {
      try {
        LOG.error(FATAL,
            "Thread " + t + " threw an Error.  Shutting down now...", e);
      } catch (Throwable err) {
        //We don't want to not exit because of an issue with logging
      }
      if(e instanceof OutOfMemoryError) {
        //After catching an OOM java says it is undefined behavior, so don't
        //even try to clean up or we can get stuck on shutdown.
        try {
          System.err.println("Halting due to Out Of Memory Error...");
        } catch (Throwable err) {
          //Again we done want to exit because of logging issues.
        }
        ExitUtil.halt(-1);
      } else {
        ExitUtil.terminate(-1);
      }
    } else {
      LOG.error("Thread " + t + " threw an Exception.", e);
    }
  }
@Test
  void testUncaughtExceptionHandlerWithRuntimeException()
      throws InterruptedException {
    final YarnUncaughtExceptionHandler spyYarnHandler = spy(exHandler);
    final YarnRuntimeException yarnException = new YarnRuntimeException(
        "test-yarn-runtime-exception");
    final Thread yarnThread = new Thread(new Runnable() {
      @Override
      public void run() {
        throw yarnException;
      }
    });

    yarnThread.setUncaughtExceptionHandler(spyYarnHandler);
    assertSame(spyYarnHandler, yarnThread.getUncaughtExceptionHandler());
    yarnThread.start();
    yarnThread.join();
    verify(spyYarnHandler).uncaughtException(yarnThread, yarnException);
  }