Source of Question33.java


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