Given below is a code snippet which will demonstrate an exception handling in Java with Divide by zero error.

public class MainClass {
  public static void main(String args[]) {

    int urAns, urDiv;

    try {

      urDiv = 0;
      urAns = 25 / urDiv;

      System.out.println("Do you really think this will print out? No! It won't!");


    catch (ArithmeticException e) {

      System.out.println("Division by zero not Possible!");


    System.out.println("This will print out after Exception Handling");




Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.