Software⏱️ 3 min read📅 2026-06-03

How to Fix: How to catch an Exception from a thread

Learn how to fix: How to catch an Exception from a thread.

Quick Answer: Try checking your system settings or restarting.

In Java, when a thread throws a RuntimeException, it cannot be caught by the main thread. This is because RuntimeException is not checked at compile time, and the JVM does not propagate it to the main thread.

This issue occurs because the main thread waits for the thread to finish using join(), but the thread has already thrown an exception and terminated its execution.

🔍 Why This Happens

  • The root cause of this issue is that RuntimeException is not propagated to the main thread. This is due to the way Java handles exceptions.
  • Another reason for this issue is that the main thread waits for the thread to finish using join(), but the thread has already thrown an exception and terminated its execution.

🚀 How to Resolve This Issue

Use a checked exception handler

  1. Step 1: In the main class, use a checked exception handler to catch the RuntimeException.
  2. Step 2: This can be done by declaring the method that starts the thread as throws RuntimeException.
  3. Step 3: For example: public void startThread() throws RuntimeException { t.start(); }

Use an uncaught exception handler

  1. Step 1: Alternatively, you can use an uncaught exception handler to catch any exceptions that occur in the main thread.
  2. Step 2: This can be done by using a try-catch block around the code that starts the thread.
  3. Step 3: For example: public void startThread() { try { t.start(); } catch (RuntimeException e) { System.out.println("** RuntimeException from thread"); } }

💡 Conclusion

To resolve this issue, you can use either a checked exception handler or an uncaught exception handler. Both methods will allow the main thread to catch and handle the RuntimeException thrown by the thread.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions