Sunday, 18 December 2022

Write a program to check the arithmetic exception by using try and catch

 


EXCEPTION HANDLING 




import java.io.*;

class exception {
    public static void main(String[] args) {
        int a = 5;
        int b = 0;
        try {
            System.out.println(a / b);
        } catch (ArithmeticException e) {
            e.printStackTrace();
        }
    }

}


OUTPUT: java.lang.ArithmeticException: / by zero

No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...