0% found this document useful (0 votes)
3 views

Exception

Uploaded by

sajood
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Exception

Uploaded by

sajood
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Custom exception type.

import java.util.*;

class DivisionByZero extends Exception


{
public String toString()
{
return ("Divide By Zero Error");
}
}// end divison

class ExceptionDemo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first value");
int a=sc.nextInt();
System.out.println("Enter the second value");
int b=sc.nextInt();
try
{
if(b==0)
throw new DivisionByZero();
double c=a/b;
System.out.println(a+"/"+b+"="+c);
} catch (DivisionByZero e)
{
System.out.println("Exception: " + e);
}

}//end main
}//end class

You might also like