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

Anonymous class' superclass' constructor throwing exception gives compiler error

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1.6
    • tools
    • x86
    • windows_nt



      Name: dbT83986 Date: 02/01/99


      Try compiling the following code:

      public class SimpleTest
      {
      SimpleTest() throws Throwable
      {
      super();
      }

      public static void main( String[] args )
      {
      try
      {
      SimpleTest test = new SimpleTest() {};
      }
      catch ( Throwable t )
      {
      t.printStackTrace();
      }
      }
      }

      This results in an error: "SimpleTest.java: 11
      Exception java.lang.Throwable must be caught, or
      it must be declared in the throws clause of this
      method."

      There is a catch for Throwable so why is it
      complaining? I think it is implicitly creating a
      constructor for the anonymous class that calls
      SimpleTest's constructor. But this implicit
      constructor does not throw the exception, hence
      the error.

      ==============================
      REVIEW NOTE 2/1/99 - User responded requesting filing as RFE

      I would still like to be able to create anonymous classes from classes whose constructors
      throw exceptions. This doesn't seem particularly difficult to implement: simply pass the
      exceptions on as the arguments are currently passed on. Can you submit this as an RFE
      please?

      Also, I don't think the nested classes spec. mentions constructor exceptions, so
      that could be clarified too.

      (Review ID: 35230)
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: