Source of Question33.java


  1: public class Question33
  2: {
  3:     public static void main(String[] args)
  4:     {
  5:         try
  6:         {
  7: //            sampleMethod(99);  //Part a
  8: //          sampleMethod(-99); //Part b
  9:           sampleMethod(0);   //Part c
 10:         }
 11:         catch(Exception e)
 12:         {
 13:             System.out.println("Caught in main.");
 14:         }
 15:     }
 16:     public static void sampleMethod(int n) throws Exception
 17:     {
 18:         try
 19:         {
 20:             if (n > 0) 
 21:                 throw new Exception( );
 22:             else if (n < 0)
 23:                 throw new NegativeNumberException( );
 24:             else 
 25:                 System.out.println("No Exception.");
 26:             System.out.println("Still in sampleMethod.");
 27:         }
 28:         catch(NegativeNumberException e)
 29:         {
 30:             System.out.println("Caught in sampleMethod.");
 31:         }
 32:         finally
 33:         {
 34:             System.out.println("In finally block.");
 35:         }
 36:         System.out.println("After finally block.");
 37:     }
 38: }