Posts

Showing posts with the label Can we throw exception from run method

Why we can not throw exception from Thread’s run method?

Image
Yes, you heard it right.   We cannot throw checked exceptions from our implemented threads run() method. Because we override Thread class’s or Runnable interface’s run() method and that method does not throw any checked exception and that’s why even we cannot throw checked exception in our overriding run() method (“Rules for method overriding” is a different topic to discuss, that I will cover separately). Now a big question comes to our mind!! Why Thread class’s or Runnable interface’s run() method declared not to throw checked exception??                                                             Before answering the above question, we need to deep dive to understand: how our implemented run() method gets invoked?? I have explained the answer in a separate post (Just to keep this post as short as possible a...