Why might a finally block be necessary?

What will be an ideal response?

At first glance, it seems as though the finally block serves no purpose. When a try block works without error, control passes to the statements that come after the catch block. Additionally, if the try code fails and throws an Exception that is caught, then the catch block executes, and control again passes to any statements that are coded after the catch block. Therefore, it seems as though the statements after the catch block always execute, so there is no need to place any statement within a special finally block. However, the last set of statements after the catch might never execute for at least two reasons:
* An Exception for which you did not plan might occur, terminating the program.
* The try or catch block might contain a statement that terminates the application.

Computer Science & Information Technology

You might also like to view...

Name the three most common Linux command shells.

What will be an ideal response?

Computer Science & Information Technology

What is a precise cursor? How can you change the cursor from Standard to Precise mode?

What will be an ideal response?

Computer Science & Information Technology