Java program to implement exception handling
A Java program to implement exception handling.
We have demonstrated try, catch and finally blocks.
Program to implement exception handling in Java
import java.util.Scanner; public class TryDemo { public static void main(String[] args) { int a,b,c=0; Scanner s = new Scanner(System.in); try { System.out.print("n Enter Divident : "); a = s.nextInt(); System.out.print("n Enter Divisor : "); b = s.nextInt(); c = a/b; System.out.println(" "+a+"/"+b+"="+c); } catch(java.util.InputMismatchException e) { System.out.println(" Input must be Integer"); } catch(java.lang.ArithmeticException e) { System.out.println(" Can't divide by zero"); } catch(Exception e) { System.out.println(e); } finally { System.out.println(" Finally block = " + c); } } }
Output

PRACTICALS/PRACTICE PROGRAM IN Java
CHECKOUT OTHER RELATED TOPICS
We are aiming to explain all concepts of Java in easiest terms as possible.

ITVoyagers
Author