Please see the following 2 programs. could you please explain me why program 1 is giving compilation errors(complaining that it is expecting catch block) while program 2 is working fine without the catch block.
Only difference is , method in program 1 is void return type, whereas method in program 2 is integer return type. Is it permitted to avoid having a catch block in the method if the return type of the method is NOT void? I am confused.
Well the first program is going to throw a checked exception to the calling method. So you need to either catch it or use a throws clause with the method. The second code will also throw a checked exception, but the return statement in the finally block will suppress that exception. So you don't need a catch block. I would recommend that you try these two modified versions of the first program