fmt/excep.java
JinalShah31 f05eec5fea hello
2019-10-31 23:41:14 +05:30

52 lines
753 B
Java

import java.util.*;
class InvalidAgeException extends Exception
{
InvalidAgeException(String s)
{
super(s);
}
}
/*class Testhrow
{
public static void validate (int age) throws InvalidAgeException
{
if(age < 18)
{
throw new InvalidAgeException("Not valid");
}
else
{
System.out.println("Valid");
}
}
}*/
class excep
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
try
{
if(age < 18)
{
throw new InvalidAgeException("Not valid");
}
else
{
System.out.println("Valid");
}
}
catch (Exception e)
{
System.out.println("Exception Occurs");
}
finally
{
System.out.println("Rest of the code");
}
}
}