How does the code enter the finally block after the try block. I know that either a finally or a catch block executes after a try block. But how does the compiler know it , i mean wouldnt it be better to enter the catch block after the try block and then in the end execute the finally block ?
remember one thing : finally block is always executable block regardless of exception.
here you Main method calls thrower method in which exceptions are thrown in all cases. but your thrower doesnt have catch block so obviuosly it travel through the finally block and the exception are caught by main method which has catch block.
to understand, introduce a catch block in your thrower method
But here there is no catch block therefore finally block is executed after try block. and in last this catch block is executed (i.e. after control returns from thrower(String s) method.
Life is easy because we write the source code.....
I added the catch block as suggested.
Here it tells me the method must return a result of type int. The only change is that I have added a catch block after the try block.