Monday, 29 June 2015

Java Custom Exception (Core JAVA)



package testing.automationTesting;

public class customException extends Exception{
 customException(){
 }
 customException(String s){
  super(s);
 }
 
static void validate(int age) throws customException{
  
  if(age<18)
   throw new customException("Invalid.Age.Format.Exception - Age should be 18");
  else if(age>18)
   throw new customException("Invalid.Age.Format.Exception - Age should be 18");
  else
   System.out.print("");
 }
 
public static void main(String[] args) {
  try{
   validate(19);
  }
  catch(Exception m){
   System.out.println("Exception is: "+m);
  }
 }
}

No comments:

Post a Comment