FINALLY BLOCK NOT EXECUTE CASE

Finally block not execute case


    More About the Finally Clause

    • A finally clause is usually included to make sure that some clean-up (e.g., closing opened files) is done.

    • A finally clause always executes when its try block executes (whether or not there is an exception). Furthermore, if the finally clause includes a transfer of control statement (return, break, continue, throw) then that statement overrides any transfer of control initiated in the try or in a catch clause. First, let's assume that the finally clause does not include any transfer of control. Here are the situations that can arise:

      • No exception occurs during execution of the try, and no transfer of control is executed in the try.
        => The finally clause executes, then the statement following the try block.

      • No exception occurs during execution of the try, but it does execute a transfer of control.
        => The finally clause executes, and then the transfer of control takes place.

      • An exception does occur during execution of the try, and there is no catch clause for that exception.
        => The finally clause executes, then the uncaught exception is "passed up" to the next enclosing try block, possibly in a calling function.

      • An exception does occur during execution of the try, and there is a catch clause for that exception. The catch clause does not execute a transfer of control.
        => The catch clause executes, then the finally clause, then the statement following the try block.

      • An exception does occur during execution of the try, there is a catch clause for that exception, and the catch clause does execute a transfer of control.
        => The catch clause executes, then the finally clause, then the transfer of control takes place.


    If the finally block does include a transfer of control, then that takes precedence over any transfer of control executed in the try or in an executed catch clause.

    Finally block Not Exception In This Case :

    javapadho
    Finally block Not Exception : case 1
    javapadho
    Finally block Not Exception : case 2