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

throws clause check is over-picky for RuntimeExceptions and Error

XMLWordPrintable

    • 1.1
    • sparc
    • solaris_2.4
    • Not verified

      The following code doesn't compile, but should. Just because t.foo wasn't
      explicit about throwing RuntimeException and Error objects doesn't mean
      that subclasses should be so restricted. u.foo is, in fact, declaring only exceptions
      that are legal to raise in t.foo:

      The code:

      class t {
          void foo() { }
      }

      class u extends t {
          void foo() throws NullPointerException { }
      }

      The error:

      t.java:6: Invalid exception class java.lang.NullPointerException in throws clause. The exception must be a subclass of an exception thrown by void foo() from class t.
          void foo() throws NullPointerException { }
               ^

            fyellinsunw Frank Yellin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: