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