How can you catch an exception thrown by another thread in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can you catch an exception thrown by another thread in Java?

How can you catch an exception thrown by another thread in Java?

25th Nov 2017, 8:24 PM
King David
1 Answer
+ 3
You can add the definition of that thread in try-catch block. or you can put the function call in different try-catch block like: try{ t1.sleep(); }catch(InterruptedException e){} try{ t2.start(); }catch(IllegalThreadStateException e){}
28th Nov 2017, 7:19 PM
Rachit Mishra
Rachit Mishra - avatar