This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Can you please explain why the exception in a() is not thrown up the call Stack and caught by the catch block in the main method. Instead, the method returns the Integer object and no exception is caught in the main method.
Class Test { public static void main(String[] args) { try { Object obj = a();
The return from the finally block overrides any previous return values as well as it also overrides any exceptions thrown. Hence the exception thrown is overriden by the object returned from the finally Block..
Originally posted by Animesh Shrivastava: Why am i not getting any compilation errors? shouldnt the method return something of type Object?
In this case the compiler can determine that an exception is always thrown from this code. Any statement after the try-catch block is unreachable under all conditions, so there's no need for a return.