Lab 8: Parameters and Java Exceptions

  1. Parameters
    1. Do Exercise 2 on Ch 18 (page 383).
    2. Do Exercise 3 on Ch 18 (page 384).
    3. Do Exercise 4 on Ch 18 (page 384).
  2. Java Exceptions
    1. We know that finally block, in Java, will always be executed. But, what if the try block stops by throwing an exception, the exception is caught and an explicit return is called? ie. What's the result of the following code?
      try {
          System.out.println(1);
          if (true) throw new Throwable();
          System.out.println(2);
      } catch(Throwable e) {
          System.out.println(3);
          if (true) return;
          System.out.println(4);
      } finally {
          System.out.println(5);
      }
      System.out.println(6);  
        
    2. What's the result of the following code? What does it return?
      try {
          System.out.println(1);
          if (true) throw new Throwable();
          System.out.println(2);
      } catch(Throwable e) {
          System.out.println(3);
          if (true) return (10);
          System.out.println(4);
      } finally {
          System.out.println(5);
          if (true) return (20);
          System.out.println(6);
      }
      System.out.println(7);
      return (30);