Monday, January 4, 2016

USER DEFINED EXCEPTION IN JAVA

USER DEFINED EXCEPTION:


import java.io.IOException;
import java.util.Scanner;
public class UserDefExcep
{
public static void main(String args[])
{
try
{
System.out.println("ENTER VALUE..");
Scanner in= new Scanner(System.in);
int a=in.nextInt();
if(a>5)
throw new Exception("value should be greather than 5");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}


}

No comments:

Post a Comment