Java thread stops with no Exception
java, multithreading
Solution
Note that an `Error` is not an `Exception`; it's a `Throwable`. So, if you `catch Exception`, `Errors` will still get through:
private void m() {
try {
m(); // recursively calling m() will throw a StackOverflowError
} catch (Exception e) {
// this block won't get executed,
// because StackOverflowError is not an Exception!
}
}
to catch "everything", change your code to this:
try {
...
} catch (Throwable e) {
// this block will execute when anything "bad" happens
}
Note that there might be little you can do if an Error occurs. Excerpt from javadoc for Error:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.
Problem
When I use 4 threads for my program there is usually no problems, but today I increased it to 8 and I noticed 1-3 threads stop working without throwing any exceptions. Is there anyway to find out why they are stopping? is there anyway to make the thread restart? This is how the structure of my thread is ``` public void run() { Main.logger.info(threadName + ": New Thread started (inside run)"); while (true) { try { //all my code //all my code //all my code } catch(Exception e) { Main.logger.error("Exception: " + e); try { Thread.sleep(10000); } catch (InterruptedException e1) { e1.printStackTrace(); } } finally { try { webClient.closeAllWindows(); Thread.sleep(3000); Main.logger.info(threadName + ": Closed browser!"); } catch (Exception e) { Main.logger.error("Exception: " + e); } } }// end while } ``` Regards!