Why is "throw null" not creating a compilation error in Java?

Viewed 6597
class ThrowNull {
    public static void main(String[] args) {
        throw null;
    }
}

We know that rule for throw is throw ThrowableInstance;, where ThrowableInstance must be an object of type Throwable or a subclass of Throwable.

Simple types, such as int or char, as well as non-Throwable classes, such as String and Object, cannot be used as exceptions. null is a special Java literal which represents a null value.

So why would throw null; compile in this code?

4 Answers
Related