Thursday, 24 November 2016

Java program to Perform Create an Own Exception.

//Java program to Perform Create an Own Exception.


import java.util.*;
import java.io.*;
class MarkInvalidException extends Exception
{
  MarkInvalidException(String message)
 {
   super(message);  
 }
}
class me
{
 public static void main(String args[])
 {
  int x;
  Scanner s=new Scanner(System.in);
   System.out.println("Enter The Mark :");
   x=s.nextInt();
   try
   {
     if(!((x>=0)&&(x<=100)))
         throw new MarkInvalidException("OutOfMark");
   }
   catch(MarkInvalidException e)
   {
     System.out.println("Caught MyOutOfMarkException");
         System.out.println(e.getMessage());
   }
   finally
   {
    System.out.println("finally over");
   }
 }

}

No comments:

Post a Comment