Try and catch & finally block - Java Program
Q. Write a Java program to use the try and catch and finally block.
In this example, we are implementing try and catch block to handle the exception. The error code written is in try block and catch block handles the raised exception. The finally block will be executed on every condition.
public static void main(String args)
int a = 40, b = 4, c = 4;
result = a / (b-c);
catch (ArithmeticException ae)
System.out.println("Cannot divided by zero."+ae);
result = a / (b+c);