I tried with System.exit(0)
but that neither executes the finally
block nor rest code.
Also tried return
that will execute finally
block but not the rest code
private static void testMethod() {
try {
System.out.println("try Block");
// Skip Finally Block.
//return;
// System.exit(0);
} catch (Exception e) {
System.out.println("catch Block");
} finally {
System.out.println("Finally Block");
}
System.out.println("After Finally Block.");
}
Output should be
try Block
After Finally Block.
OR
try Block
catch Block
After Finally Block.