In this programe MyclassEx is child class of Exception(java.lang.Exception).we create user define exception.In the class contain a parameterized constructor who pass its argument to super class that is Exception class.outside this class I declare another class SimpleThrow.here i take input of two variable x,y of double type.and Z is divident of x,y.if i take y as zero it should throw the control to catch(ArithmeticException e)block.but it do not throw any of the catch block except the user defined Exception i.e,MyclassEx.How can I make all catch block active with the Myclass exception?
import java.lang.Exception;
import java.util.*;
class MyclassEx extends Exception{
MyclassEx(String msg)
{
super(msg);
System.out.println(msg);
}
}
public class SimpleThrow
{
public static void main(String[] args)
{
try
{
double x=0,y=0,z=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter two numbers:");
x=sc.nextDouble();
y=sc.nextDouble();
z=x/y;
if(z<0.01)
{
**throw new MyclassEx("Number is too small");**
}
}
catch(MyclassEx e)
{
System.out.println("caught exception");
}
catch(ArithmeticException obj)
{
System.out.println("division not possible BY 0");
}
catch(InputMismatchException e2)
{
System.out.println("you have entered wrong key:");
}
finally
{
System.out.println("yoo");
}
}
}
D:\debolina\java\Error_handling>javac SimpleThrow.java D:\debolina\java\Error_handling>java SimpleThrow Enter two numbers:45 0 yoo