@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 testUncaughtExceptionHandlerWithError()
      throws InterruptedException {
    ExitUtil.disableSystemExit();
    final YarnUncaughtExceptionHandler spyErrorHandler = spy(exHandler);
    final java.lang.Error error = new java.lang.Error("test-error");
    final Thread errorThread = new Thread(new Runnable() {
      @Override
      public void run() {
        throw error;
      }
    });
    errorThread.setUncaughtExceptionHandler(spyErrorHandler);
    assertSame(spyErrorHandler, errorThread.getUncaughtExceptionHandler());
    errorThread.start();
    errorThread.join();
    verify(spyErrorHandler).uncaughtException(errorThread, error);
  }