finally in Exception Handling in Java
finally block always executes after try block. So finally block will be executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return , continue , or break . You can put cleanup code in a finally block that is always a good practice, even when no exceptions are anticipated. public void writeData() { PrintWriter out = null; try { System.out.println("Entering try statement"); out = new PrintWriter( new FileWriter("myFile.txt")); for (int i = 0; i < SIZE; i++) out.println("Value at: " + i + " = " + vector.elementAt(i)); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("ArrayIndexOutOfBoundsException: " + e.getM...