Wednesday, 20 July 2011

Exception



import java.io.*;
class ExceptionClass extends Exception
{
            String Error;
            ExceptionClass(String ErrorMsg)
            {
                        super(ErrorMsg);
                        Error=ErrorMsg;
            }          
            public String toString()
            {
                        return "ExceptionClass :: { " + Error + "} ";
            }
}
class ExClass
{
            public static void main(String args[]) //throws Exception
            {
                        try
                        {
                                    InputStreamReader isr=new InputStreamReader(System.in);                                
                                    BufferedReader br=new BufferedReader(isr);     
                                    int a=Integer.parseInt(br.readLine());
                                    int b=Integer.parseInt(br.readLine());
                                    if(b==0)
throw new ExceptionClass("Oops ! This division is not possible. Please Try Again !!!");   
                                    if((a-b)<=0)
throw new ExceptionClass("Oops ! (a-b) should always be greater than 0 !!!");                                                     
                                    if(a<100 || b<100 )
                                                throw new ExceptionClass("a and b should be greater than 100  !!!");                                                                              
                        }
                        catch(ExceptionClass e)
                        {
                                    System.out.println("Exception generated : \n" +e);
                        }
                        catch(Exception e)
                        {
                                    System.out.println("System generated Exception : \n" +e.getMessage());
                        }
            }
}

No comments:

Post a Comment