void uncaughtExceptionInternal(
      final Thread t,
      final Throwable e,
      final SystemExit systemExit) {
    if (t instanceof StreamThread) {
      countDownLatch.ifPresent(CountDownLatch::countDown);
      return;
    }
    log.error("Unhandled exception caught in thread {}.", t.getName(), e);
    System.err.println(
        "Unhandled exception caught in thread: " + t.getName() + ". Exception:" + e.getMessage());

    flusher.run();

    systemExit.exit(-1);
  }
@Test
  public void shouldNotSystemExitWhenStreamThreadThrowsAnError() throws InterruptedException {
    // When
    final CountDownLatch latch = new CountDownLatch(1);
    KsqlUncaughtExceptionHandler handler = new KsqlUncaughtExceptionHandler(LogManager::shutdown, Optional.of(latch));
    handler.uncaughtExceptionInternal(streamThread, new Exception(), new MockSystemExit());
    // Then
    assertThat(latch.await(60000, TimeUnit.MILLISECONDS), is(true));
  }