|
User Thrown Exception
import java.util.*;
public class UserExceptionThrow
{
int n;
UserExceptionThrow(int n)
{
this.n = n;
}
int calculate() throws NumberFormatException
{
Random r;
r = new Random();
int x = r.nextInt();
int y = r.nextInt();
if (x > 100000)
throw new NumberFormatException("X Leads to be
Greater than One Lakh");
try
{
n *= x / y;
}
catch(ArithmeticException e)
{
System.out.println("Division by Zero");
}
catch(NumberFormatException e)
{
System.out.println("X Leads to be Greater than One
Lakh");
}
return n;
}
public static void main(String arg[])
{
UserExceptionThrow u;
u = new UserExceptionThrow(1000);
while (u.n < 10000)
{
u.n =u.calculate();
}
}
}
Output
:
X Leads to be Greater than One Lakh
|