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...

What is the daemon for running Apache Web Server?

A. Tcpd B. Xinetd C. Sshd D. Httpd

Computer Science & Information Technology

Which command displays a file's contents one screen at a time?

A. head B. show C. echo D. more

Computer Science & Information Technology

Web page templates can use the ____________________ function within a conditional or switch statement to display dynamic content from different include files within the same section of the template.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The ____ function calculates a total of the values in a column.

A. TOTAL B. CALCULATE C. SUM D. ADD

Computer Science & Information Technology