0

My program dies in a thread without throwing an exception right in the middle of my code. I tried to install an UncaughtExceptionHandler and capture exception but nothing is caught.

Thread.currentThread().setUncaughtExceptionHandler(new DeathWatcher());
try {
   LOG.info("Start =========");
   dyingMethod();
   LOG.info("End ==========="):
} catch (Throwable e)  {
    LOG.error(e.getMessage());
    throw e;
}

The code will print Start in the log but no End.

What would cause a thread to die before completion without an exception?

ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • Is it possible that `dyingMethod()` results in a call to `System.exit()` somehow? – JonK Aug 30 '19 at 15:32
  • Is this a separately spawned thread or the main thread? You seem to already know which method or thread is dying - does this mean you know how to reproduce the problem? – Thomas Aug 30 '19 at 15:37
  • That would cause the JVM to quit. The main thread is still running afterwards, just one thread dies. – ZZ Coder Aug 30 '19 at 15:38
  • Does your program actually exit, or does it get caught in a loop? – arcadeblast77 Aug 30 '19 at 15:41
  • The program spawns a thread to run the `dyingMethod`. The thread dies but the program is still running. – ZZ Coder Aug 30 '19 at 15:43
  • Are you sure that thread died instead of hanging? have you created thread dump to be sure? – Ivan Aug 30 '19 at 15:47
  • Yeah. I can confirm the thread is dead. I can see it disappear in Intellij debugger. – ZZ Coder Aug 30 '19 at 15:53
  • 2
    @ZZCoder Please provide a [reprex]. The code you've provided is insufficient to determine what's going on. – Avi Aug 30 '19 at 15:56
  • Sorry. I wasn't able to make a reproducible example without using some proprietary libraries. The problem is most likely in those libraries. – ZZ Coder Aug 30 '19 at 17:30

0 Answers0