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

throw null gives bizarre error message

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • tools
    • None
    • beta
    • generic
    • generic
    • Verified

      Consider the program:

      class ThrowNull {

        void foo() throws Throwable {
          throw(Throwable) null;
        }


        void bar() throws Throwable {
          throw null;
        }
      }

      Compiling this yields:

      javac ThrowNull.java
      ThrowNull.java:8: unreported exception <null>; must be caught or declared to be thrown
          throw null;
          ^
      1 error

      The literal null is an element of every type, including Throwable. The program
      should compile without error; it is legal.


      gilad.bracha@eng 2000-04-08

            busersunw Btplusnull User (Inactive)
            gbrachasunw Gilad Bracha (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: