henry joe wrote:I was just wondering why this piece of code will throw an Error.
Because of
Thread "t1" created at line no. 17 will execute the run() method;Because of t1.start();. Now in run method, there is for loop and in it for i==2 you will create a new thread and called up start() to execute its run method (So, currently there are two runnable threads). After creation of it there is an explicit throw sentence. So t1 will be terminated with Error. But a new thread is alive their, which will again create a new one and throw an error. So, you will get infinite results of Errors and 0 1...