...

/

Finally Using Finally

Finally Using Finally

We'll walk through the syntax and the usage of finally.

The finally block is a block that will be executed whether or not the exception is thrown/handled. It is useful to release resources, close connections, or close files.

Syntax:

class Exceptions {
    public static void main( String args[] ) {
        
        try{
          
        }catch(Exception e){
          // exception is caught here
        }finally{ // this is an optional block
          // will always be executed
        }
    }
}

...