This question already has answers here: Why is “throw null” not creating a compilation error in Java? (4 answers) Closed last year .

When running this:

public class WhatTheShoot { public static void main(String args[]){ try { throw null; } catch (Exception e){ System.out.println(e instanceof NullPointerException); System.out.println(e instanceof FileNotFoundException); } } }

The response is:

true false

Which was fairly stunning for me. I would have thought this would net a compile-time error.

Why can I throw null in Java, and why does it upcast it to a NullPointerException?

(Actually, I don't know if it is an "upcast", given I'm throwing null)

Aside from a really really stupid interview question (please nobody ask this in an interview) I cannot see any reason to throw null . Maybe you want to be fired, but that's... I mean, why else would anyone throw null ?