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

Misleading error message when superclass constructor has throws clause

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.4.2
    • 1.1.3
    • tools
    • mantis
    • generic
    • solaris_7

      The following program

      > package bug;
      >
      > class SuperClass
      > {
      > SuperClass() throws Exception { throw new Exception(); }
      > }
      >
      > public class Bug extends SuperClass
      > {
      > // Comment in the following line to make javac compile.
      > // Bug() throws Exception {}
      > }

      leads to the following error message:

      > bug/Bug.java:8: unreported exception: Exception; must be caught or
      declared to be thrown
      > public class Bug extends SuperClass
      > ^
      > 1 error

      Ok, class Bug must define a constructor that
      throws the same exception as the superclass
      constructor does; then the program compiles.
      But the error message is quite misleading, if you
      do not recognize the problem.

            gafter Neal Gafter (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: