I am searching on net but did not get satisfactory answers that what made Sun engineers to disallow run method of Runnable interface for throwing an exception.
-
The `run` method is `Runnable`'s. – Sotirios Delimanolis Aug 20 '14 at 06:06
-
Which portion of your program would catch such an exception? – Seelenvirtuose Aug 20 '14 at 06:08
-
@thd Which it implements from `Runnable`. – Sotirios Delimanolis Aug 20 '14 at 06:08
-
@TheLostMind [nitpicky] It's still `Runnable`'s method because a `Thread` _is a_ `Runnable`. [/nitpicky] – Seelenvirtuose Aug 20 '14 at 06:10
-
Welcome to [so]. Questions here are expected to be __specific programming problems__ expressed _clearly_. Please take a __[tour]__. – Unihedron Aug 20 '14 at 07:16
6 Answers
The intention behind the concept of multi-threading is to allow parallel processing of two or more tasks for which the run method is used. If the run
method throws a CheckedException
, in that case the calling thread has to wait in the corresponding catch block to wait for the same which defies the sole purpose of multi-threading.
For example
: Consider the following HYPOTHETICAL scenario
The main thread
starts another thread say Thread1
which supposedly say does throw some CheckedException
. Now to catch that exception, the corresponding catch block has to be put somewhere. Lets say the main method itself has the same. Now to catch that exception (generate by the Thread1's run method), the main thread has to wait inside the catch block to let the execution of Thread1's run method complete which will not be acceptable as then there would be no use of multithreading here.
Moreover the Future and Callable tasks are based on the above hypothesis only.

- 575
- 1
- 5
- 19
The answer to the question can be a question to ask yourself that if run method throws an exception then what would catch it?
From the JCIP docs:
Runnable is a fairly limiting abstraction; run can not return a value or throw checked exception .
However you can use Callable
, and submit it to an ExecutorService
and waiting for result with FutureTask.isDone()
returned by the ExecutorService.submit()
Something like this:
Callable<Void> callable = new Callable<Void>() {
public Void call() {
// whatever you want
return null;
}
};

- 168,305
- 31
- 280
- 331
To fill that gap since Jdk 1.5 onwords Callable<V>
is introduced which provides you create async task and that returns a result and may throw an exception.
Code snippet -
public class MyCallable implements Callable<String> {
@Override
public String call() throws Exception {
...
}
}
...
FutureTask<String> futureTask1 = new FutureTask<String>(new MyCallable());
ExecutorService executor = Executors.newFixedThreadPool(1);
executor.execute(futureTask1);
try{
String result = futureTask1.get();
...
}catch(Exception ex){ // catch that exception
}

- 40,646
- 13
- 77
- 103
-
Callable was added when you can add individual tasks to an Executor where you can capture the result in a Future and any exception thrown. – Rahul Tripathi Aug 20 '14 at 06:08
-
The calling method does not call the run()
directly to start a Thread
. One needs to call Thread.start()
which in turn calls a run()
method. So there is no point in throwing an checked exception from the run()
method.
Also, any exception you throw in run method will be carefully ignored by JVM. Thus, throwing it there is probably a mistake (unless you have specific exception handler for the thread)
Refer this for more explanation: Java Thread: Run method cannot throw checked exception

- 1
- 1

- 7,746
- 2
- 28
- 38
-
we can catch after the thread is started . By enclosing thread.start() in try catch. – T-Bag Aug 20 '14 at 06:40
Checked Exception vs Unchecked Exception.
The first point is a wrong assumption that run()
method cannot throw an exception. See the below code compiles
public class Test extends Thread{
@Override
public void run() throws IllegalArgumentException {
// TODO Auto-generated method stub
super.run();
}
}
And now see the below code , which is won't compile.
public class Test extends Thread{
@Override
public void run() throws FileNotFoundException {
// TODO Auto-generated method stub
super.run();
}
}
The point is the run() nethod cannot throws a Checked Exception, If it can throw which Exception we would catch ??

- 120,458
- 37
- 198
- 307
-
If main() allows us to throw exception and JVM handles it then why not JVM handles run() exception. – T-Bag Aug 20 '14 at 06:39
if any calling method(for example void m1()) throws exception called method (pp.m1()) has to either solve or rethrow the exception just follows////
public class Practice14 {
public void m1() throws Exception{
System.out.println("hello");
}
public static void main(String[] args) {
Practice14 pp=new Practice14();
try {
pp.m1();//here solving the exception
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
so because start() method in thread doesn't have capability to solve the exception run method won't allow you to throws exception

- 196
- 1
- 4