WAP that creates a custom exception InvalidAgeException which will be thrown when user enters age below 18.
WAP that creates a custom exception InvalidAgeException which will be thrown when user enters age below 18.
import java.util.Scanner;
class Exc
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
System.out.println(" enter your age");
int age = s.nextInt();
try
{
if(18<age)
throw new ArithmeticException("your age is 18+");
else
System.out.println("you age considered") ;
}
catch(ArithmeticException e)
{
System.out.println("Exception is="+ e.getMessage());
}
System.out.println("bs have ");
}
}
import java.util.Scanner;
class Exc
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
System.out.println(" enter your age");
int age = s.nextInt();
try
{
if(18<age)
throw new ArithmeticException("your age is 18+");
else
System.out.println("you age considered") ;
}
catch(ArithmeticException e)
{
System.out.println("Exception is="+ e.getMessage());
}
System.out.println("bs have ");
}
}
Comments
Post a Comment