0% found this document useful (0 votes)
8 views1 page

Custom Exception Handling in Java

Uploaded by

sajood
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Custom Exception Handling in Java

Uploaded by

sajood
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Custom exception type.

import [Link].*;

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([Link]);
[Link]("Enter the first value");
int a=[Link]();
[Link]("Enter the second value");
int b=[Link]();
try
{
if(b==0)
throw new DivisionByZero();
double c=a/b;
[Link](a+"/"+b+"="+c);
} catch (DivisionByZero e)
{
[Link]("Exception: " + e);
}

}//end main
}//end class

You might also like