So, you mean to say that if we put "throw e1;" in a try catch block the program should compile?
I tried that -- but I got the same error -- Statement unreachable.
Originally posted by Chandra Bhatt:
catching the exception and declaring it is different. if main declares that it throws particular exception, you need not to place the code in the try catch block that throws the exception; because main declares that it throws it. Your first statement goes wrong "main must catch every exception".
You have only two options anywhere:
1- catch it using try catch block ofcourse.
2- declare it in the method that is throws the exception so that that need not to place the code in the try catch block; this phenomenon is called ducking;
Thanks and Regards,
Similar, is the situation with the original code..main() declares that it'll throw MyException. and it does throw MyException e1 in finally block.
Then, why was there a need to put throw in try-catch for the code to compile properly