Kaleem Anwar wrote:
So, what I am understanding from this is, you cant place a checked exception in catch argument unless Try block must throw it. How is that , kindly explain?
Your understanding is correct. You cannot catch an exception that is not thrown within the associated try block.
Why? Well, there would not be any point having code there to catch an exception that can never be thrown. The code would be redundant and the compiler is smart enough to tell you so you can remove it.
Redundant code is not desirable. Every line of code adds a risk of bugs and carries a maintenance overhead. And in principle every code path should be tested, so a redundant code path would require adding a redundant
test!