Discussions

Web tier: servlets, JSP, Web frameworks: How to throw exception from Thread.run() method to the caller

  1. I want to throw exception in Thread.run() method. How can I do that ?
    If I try to compile the Code given below, it does not allow me to compile :

    public class ThreadTest {
    public static void main(String[] args) {
    ThreadTest.DyingThread t = new DyingThread();
    t.start();
    }

    static class DyingThread extends Thread {
    public void run() {
    try {
    //some code that may throw some exception here
    } catch (Exception e) {
    throw e;//Want to throw(pass) exception to caller
    }
    }
    }
    }
  2. Use UnChecked Exceptions and ThreadGroup.