I would like to point out that there is also this little trick besides the question scope.
Code: Select all
public static int doIt() throws Exception{
throw new Exception("Forget It");
}
If the question were something like: The method doIt() does not compile. true or false.?
What would you have replied?
Fantastic question so you can exercise also in tricky unreachable code things.
In this case the "return" statement must be omitted either before or after the Exception throwing itself.
If "return" had been used in either above or below the "throw new Exception" statement it would not have compiled at all as it would have given a compilation error due to unreachableness of the code.
The_Nick