/**********************************************************************
* @description : Exception handling
*
* This class demonstrates generation of five types of exceptions
* and the code to handle these exceptions. The demonstarted exceptions 
are:
* - array index out of bounds
* - division by zero
* - file not found
* - illeagal access exception
* - null pointer exception
*
*
*
* @author Ravi Bhatia
* @date 01/17/2006
* LAB3, Section1
*
***********************************************************************/
public class DemoExceptionHandling
{

   public static void main (string[] args)
      {
      
  		System.out.println("This program demonstrates exception handling with five different types of exceptions");
		    
		
		        
      /********************************************************
      * this method generates an 'array index out of bounds' exception
      */
      System.out.println;
		System.out.println("Demo of 'Array index ot of bounds exception'");
		System.out.println("The Array has three elements adn we attempt to print four");
				
		int demoArray[]= {1,2,3};
		
        try
         {
			system.out.println("elements of the array are: ");
        
		   for(i=0;i<3;i++)
			{
			System.out.println(demoArray[i]);
			}
			
         }
         
            catch(ArrayIndexOutOfBoundsException aioob)
            {
            system.out.println("Array index has gone out of bounds);
            }
      
     
	  
	   /*
      /**********************************************************
      * this method generates a 'division by zero' exception
      */
      	System.out.println;
			System.out.println("Demo of 'Arithmetic Exception - division by zero");
			
			int Zero;
         try
         {
         system.out.println("the quotients as 100 is divided by integers from 5 to 0 are:");
			
			for(i=5;i>=0;i--)
			{
			system.out.println("100/"+i+" = "+100/i);
			}
         }
         
             catch(ArithmeticException dbz)
            {
            system.out.println("division by zero has occured");
            }
      
      
      
      /******************************************************
      * this method generates a 'File not found' exception
      */
      	System.out.println;
			System.out.println("Demo of 'File not found exception'");
			System.out.println("You will be asked to enter a file name. Enter an existing file name 'correctFile.txt' and then try with any other file name");
			
			String enteredFileName; 
			Scanner fileNameScanner; 
			Scanner keyboard; 
			int integer; 
			keyboard = new Scanner(System.in); 
			System.out.println (" Please enter your file name and hit enter "); 
			enteredFileName = keyboard.nextLine(); 
			System.out.println (" The name of the file you want to open is " + enteredFileName);
 
         try
         {
            fileNameScanner = new Scanner (new File (enteredFileName)); 
				
				while (fileNameScanner.hasNextInt()) 
				{ 
				integer = fileNameScanner.nextInt(); 
				System.out.println (" The value you got from the file is " + integer);
				}

         
            
         }
             catch(FileNotFoundException fnf)
            {
            system.out.println("File could not be found");
            }
      
      
      /************************************************************
      * this method generates an 'illegal access' exception
      */
      
         try
         {
         
         } 
         
             catch(Exception ia)
            {
            
            }
      
      
      
      /*************************************************************
      * this method generates a 'null pointer exception'
      */
      
         try
         {
         
         }
         
             catch(Exception np)
            {
            
            }
      
      
      
         system.out.println("Demonstration completed");
      
      */
      }
}   
