Possible Duplicate:
What is the best approach to handling exceptions thrown in a separate thread?
When bad things happen, my code throws an Exception, that is later being caught and handled.
If said code runs as part of a thread however, public void run() does not throw Exception. How can the executor of the tread know about exception being thrown?
Now:
A a = new A();
try {
a.doSomething();
} catch (Exception e) {
// do something clever
}
With Threads
Thread t = new Thread (new A());
t.start(); // run() calls doSomething()
If this threads fails with exception, how can i know about it?
You can use an ExecutorService
if you don’t have anything to return you can use the following.