Write a java program to know above exception details using getMessage Method

Write a java program to know above exception details using getMessage Method

Program
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        int x,y,z;
        System.out.println("Enter x,y values :");
        Scanner s=new Scanner (System.in);
        try
        {
            x=s.nextInt();
            y=s.nextInt();
            z=x/y;
            System.out.println("Division of two number is : "+z);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

Output:

Enter x,y values :10 0
/ by zero


Exception Handling In Java



More Questions


167 . Write a java program to know above exception details using getMessage Method
168 . Write a Throws Keyword Program
169 . Write a Finally block Program
170 . Write a program to handle negative age exception
171 . Write a program to handle negative salary exception
172 . Write a Simple interest program to handle negative amount and duration and interest using user defined exception
173 . Write a String length program
174 . Write a string charAt() method program
175 . Write a string toLowerCase() Program
176 . Write a String toUpperCase() program
177 . Write a string concat() program