kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Exception in thread "main" java.lang.ArithmeticException: / by zero
at KW.main(KW.java:6)
kodingwindow@kw:~$
Java program to handle the ArithmeticException
KW.java
classKW{publicstaticvoidmain(Stringargs[]){intn=515,d=0;try{intresult=n/d;}catch(ArithmeticExceptione){System.out.println("Can't divide by zero");}}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Can't divide by zero
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.