Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4087302

The reachability of catch blocks is not explicitly defined or is undefined.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.1.4, 1.2.0
    • tools
    • x86, sparc
    • solaris_2.6, windows_95

    Description


      allan.jacobs@Eng 1997-10-20

      The following example is motivated by Modena test n1419206.

      // import java.io.IOException;
      class X {
        static void check_unexception () {
          try{ }
          catch( Exception e) { System.out.println(e); }
        }
        static void check_unreachable () {
          try{ }
          catch( Throwable e) { System.out.println(e); }
        }
        public static void main( String[] argv ) {
          X.check_unthrowable();
          X.check_unexception();
        }
      }

      Section 14.19:
      "A catch block C is reachable iff both of the following are true:
      * Some expression or throw statement in the try block is reachable and
        can throw an exception whose type is assignable to the parameter of the
        catch clause C. (An expression is considered reachable iff the
        innermost statement containing it is reachable.)
      * There is no earlier catch block A in the try statement such that the
        type of C's parameter is the same as or a subclass of the type of A's
        parameter.

      Are the println's reachable? Javac says so but the spec (at least by
      the most direct reading) says not. Which catch block arguments do make
      their catch block's unreachable when their corresponding try blocks are
      empty?

      =========================================================================
      Here's another test case from ###@###.###. I would expect this one to fail at compile-time also.
      brian.klock@eng 1998-07-23

      //-----------------------------Test1.java---------------------------
      public class Test1 {
          public static void main(String args[]) throws Exception
          {
              try { throw new Exception(); }
              catch(SubException e) { System.out.println("Caught 1"); }

              try { m(); }
              catch(SubException e) { System.out.println("Caught 2"); }
          }

          static void m() throws Exception { throw new SubException(); }
      }

      class SubException extends Exception { }

      Attachments

        Issue Links

          Activity

            People

              wmaddoxsunw William Maddox (Inactive)
              ajacobssunw Allan Jacobs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: