finally block is coded after a try catch block. The statements in the
finally block are executed unconditionally, i.e., regardless of whether an exception was thrown. To learn how to use the
finally block in Java, follow these five steps.
finallyblock is present after the
catch. The statement in the block will execute whether or not an
ArrayIndexOutOfBoundsExceptionwas thrown because the
argsarray is empty. The program caught the exception and displayed an error message. Notice the output of the
finallyblock is displayed as well.
argsarray had one item. Again, the output of the
finallyblock is displayed.