Finally block in Java

By | September 29, 2021
Finally block in Java

Java allows the use of the finally block that allows you to execute the critical code. This block will always get executed whether the exception is handled or not. Finally block will always come after the try and catch block. Generally, the finally block is used for the code like cleanup like closing file, connection etc.


import java.util.regex.*;  
public class Simple{  
public static void main(String args[]){  
   int val=25/4;  
  catch(NullPointerException e){System.out.println(e);}  
  finally{System.out.println("finally block");}  
  System.out.println("rest code");  


Finally block in Java examples

People are also reading: 


Leave a Reply

Your email address will not be published.